Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve performance of get_conceptscheme. Refs #71 #72

Merged
merged 1 commit into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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