Changeset - b599ddee5de9
[Not reviewed]
0 1 0
Brett Smith - 3 years ago 2021-03-06 14:33:10
brettcsmith@brettcsmith.org
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.
1 file changed with 15 insertions and 11 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/reports/query.py
Show inline comments
...
 
@@ -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
 

	
 

	
0 comments (0 inline, 0 general)