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,7 +83,10 @@ 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)
logger.debug("books loaded from Beancount")
if self.rewrite_rules:
for index, entry in enumerate(result.entries): for index, entry in enumerate(result.entries):
# entry might not be a Transaction; we catch that later. # entry might not be a Transaction; we catch that later.
# The type ignores are because the underlying Beancount type isn't # The type ignores are because the underlying Beancount type isn't
@ -95,6 +98,7 @@ class BooksLoader:
result.entries[index] = entry._replace(postings=list(postings)) # type:ignore[call-arg] result.entries[index] = entry._replace(postings=list(postings)) # type:ignore[call-arg]
except AttributeError: except AttributeError:
pass pass
logger.debug("rewrite rules applied")
return result return result