Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(290): Cache previous/next/etc. in VersionClassBase
Browse files Browse the repository at this point in the history
Cache some properties in VersionClassBase as it won't really change
and can improve performance significantly by avoiding extra queries

Tested this in my own application and also in a shell:
>>> class A:
...     @cached_property
...     def abc(self):
...         print("test")
...         return 1
...
>>> a = A()
>>> a.abc
test
1
>>> a.abc
1
AbdealiLoKo committed Aug 28, 2022
1 parent 38cef84 commit e93cde3
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -64,7 +64,8 @@ def get_version():
platforms='any',
install_requires=[
'SQLAlchemy>=1.0.8',
'SQLAlchemy-Utils>=0.30.12'
'SQLAlchemy-Utils>=0.30.12',
'cached-property'
],
extras_require=extras_require,
classifiers=[
7 changes: 4 additions & 3 deletions sqlalchemy_continuum/version.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import sqlalchemy as sa
from cached_property import cached_property

from .reverter import Reverter
from .utils import get_versioning_manager, is_internal_column, parent_class


class VersionClassBase(object):
@property
@cached_property
def previous(self):
"""
Returns the previous version relative to this version in the version
@@ -18,7 +19,7 @@ def previous(self):
.previous(self)
)

@property
@cached_property
def next(self):
"""
Returns the next version relative to this version in the version
@@ -31,7 +32,7 @@ def next(self):
.next(self)
)

@property
@cached_property
def index(self):
"""
Return the index of this version in the version history.

0 comments on commit e93cde3

Please sign in to comment.