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:
parent
9c943bc8a9
commit
b599ddee5d
1 changed files with 15 additions and 11 deletions
|
@ -83,18 +83,22 @@ class BooksLoader:
|
|||
self.rewrite_rules = rewrite_rules
|
||||
|
||||
def __call__(self) -> books.LoadResult:
|
||||
logger.debug("BooksLoader called")
|
||||
result = books.Loader.dispatch(self.books_loader, self.start_date, self.stop_date)
|
||||
for index, entry in enumerate(result.entries):
|
||||
# entry might not be a Transaction; we catch that later.
|
||||
# The type ignores are because the underlying Beancount type isn't
|
||||
# type-checkable.
|
||||
postings = data.Posting.from_txn(entry) # type:ignore[arg-type]
|
||||
for ruleset in self.rewrite_rules:
|
||||
postings = ruleset.rewrite(postings)
|
||||
try:
|
||||
result.entries[index] = entry._replace(postings=list(postings)) # type:ignore[call-arg]
|
||||
except AttributeError:
|
||||
pass
|
||||
logger.debug("books loaded from Beancount")
|
||||
if self.rewrite_rules:
|
||||
for index, entry in enumerate(result.entries):
|
||||
# entry might not be a Transaction; we catch that later.
|
||||
# The type ignores are because the underlying Beancount type isn't
|
||||
# type-checkable.
|
||||
postings = data.Posting.from_txn(entry) # type:ignore[arg-type]
|
||||
for ruleset in self.rewrite_rules:
|
||||
postings = ruleset.rewrite(postings)
|
||||
try:
|
||||
result.entries[index] = entry._replace(postings=list(postings)) # type:ignore[call-arg]
|
||||
except AttributeError:
|
||||
pass
|
||||
logger.debug("rewrite rules applied")
|
||||
return result
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue