query: Skip rewrite rule logic when none are loaded.

This saves a few seconds of load time for the user on each run and is easy
to implement, so it's worth it.
This commit is contained in:
Brett Smith 2021-03-06 09:33:10 -05:00
parent 9c943bc8a9
commit b599ddee5d

View file

@ -83,18 +83,22 @@ class BooksLoader:
self.rewrite_rules = rewrite_rules self.rewrite_rules = rewrite_rules
def __call__(self) -> books.LoadResult: def __call__(self) -> books.LoadResult:
logger.debug("BooksLoader called")
result = books.Loader.dispatch(self.books_loader, self.start_date, self.stop_date) result = books.Loader.dispatch(self.books_loader, self.start_date, self.stop_date)
for index, entry in enumerate(result.entries): logger.debug("books loaded from Beancount")
# entry might not be a Transaction; we catch that later. if self.rewrite_rules:
# The type ignores are because the underlying Beancount type isn't for index, entry in enumerate(result.entries):
# type-checkable. # entry might not be a Transaction; we catch that later.
postings = data.Posting.from_txn(entry) # type:ignore[arg-type] # The type ignores are because the underlying Beancount type isn't
for ruleset in self.rewrite_rules: # type-checkable.
postings = ruleset.rewrite(postings) postings = data.Posting.from_txn(entry) # type:ignore[arg-type]
try: for ruleset in self.rewrite_rules:
result.entries[index] = entry._replace(postings=list(postings)) # type:ignore[call-arg] postings = ruleset.rewrite(postings)
except AttributeError: try:
pass result.entries[index] = entry._replace(postings=list(postings)) # type:ignore[call-arg]
except AttributeError:
pass
logger.debug("rewrite rules applied")
return result return result