Skip to content

Commit

Permalink
Improve performance of get_conceptscheme. Refs #71 (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
koenedaele authored May 25, 2020
1 parent 92d57b8 commit 11e42ad
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
3 changes: 2 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
0.6.0 (2020-03-18)
0.6.0 (2020-??-??)
------------------

* Update to the latest skosprovider version and implement the
Expand All @@ -9,6 +9,7 @@
issue we wanted it to fix and it added a lot of overhead. A provider should
now be passed a :class:`sqlachemy.orm.session.Session` at startup, or a
callable that returns such a session. (#64)
* Improved performance of getting the concept_scheme by caching it. (#71)
* Drop support for Python 3.4. Add support for Python 3.7. This
is also the last version to support Python 2. (#62)

Expand Down
10 changes: 9 additions & 1 deletion skosprovider_sqlalchemy/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class SQLAlchemyProvider(VocabularyProvider):
as backend.
'''

_conceptscheme = None
'''
The concept scheme, once it has been loaded. Should never be accessed
directly.
'''

expand_strategy = 'recurse'
'''
Determines how the expand method will operate. Options are:
Expand Down Expand Up @@ -96,7 +102,9 @@ def __init__(self, metadata, session, **kwargs):

@property
def concept_scheme(self):
return self._get_concept_scheme()
if self._conceptscheme is None:
self._conceptscheme = self._get_concept_scheme()
return self._conceptscheme

def _get_concept_scheme(self):
'''
Expand Down
8 changes: 8 additions & 0 deletions tests/test_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ def test_concept_scheme(self):
assert 2 == len(cs.languages)
assert 'en' in cs.languages

def test_concept_scheme_is_cached(self):
from skosprovider.skos import (
ConceptScheme
)
assert self.provider._conceptscheme is None
cs = self.provider.concept_scheme
assert self.provider._conceptscheme == cs

def test_get_concept_by_id(self):
from skosprovider.skos import Concept

Expand Down

0 comments on commit 11e42ad

Please sign in to comment.