kvesteri / sqlalchemy-continuum

Versioning extension for SQLAlchemy.
BSD 3-Clause "New" or "Revised" License
580 stars 126 forks source link

Caching the version.previous attribute #290

Open AbdealiLoKo opened 2 years ago

AbdealiLoKo commented 2 years ago

Currently, the version.previous attribute is calling VersionObjectFetcher.previous Which runs: self.previous_query(obj).first()

Because it is using .first() - a query is running every time.

It would be a nice developer experience to cache this so it does not call multiple queries.

Currently I need to do:

current = ...
previous = current.previous

And then pass it all around in my functions to avoid performance issues. It would make my code a lot simpler if the previous property cached the value so I did not need to save it in my own separate variable