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

feat(case_cache): make case cache optional #228

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
47 changes: 29 additions & 18 deletions gdcdatamodel/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from .caching import (
NOT_RELATED_CASES_CATEGORIES,
RELATED_CASES_LINK_NAME,
CACHE_CASES,
cache_related_cases_on_update,
cache_related_cases_on_insert,
cache_related_cases_on_delete,
Expand Down Expand Up @@ -339,15 +340,16 @@ def node_id(self, value):

# _related_cases_from_parents: get ids of related cases from this
# nodes's sysan
attributes['_related_cases_from_cache'] = property(
related_cases_from_cache
)
if CACHE_CASES:
attributes['_related_cases_from_cache'] = property(
related_cases_from_cache
)

# _related_cases_from_parents: get ids of related cases from this
# nodes parents
attributes['_related_cases_from_parents'] = property(
related_cases_from_parents
)
# _related_cases_from_parents: get ids of related cases from this
# nodes parents
attributes['_related_cases_from_parents'] = property(
related_cases_from_parents
)

# Create the Node subclass!
cls = type(name, (Node,), dict(
Expand Down Expand Up @@ -459,17 +461,26 @@ def EdgeFactory(name, label, src_label, dst_label, src_dst_assoc,
_assigned_association_proxies[dst_label].add(dst_src_assoc)
_assigned_association_proxies[src_label].add(src_dst_assoc)

hooks_before_insert = Edge._session_hooks_before_insert + [
cache_related_cases_on_insert,
]

hooks_before_update = Edge._session_hooks_before_update + [
cache_related_cases_on_update,
]
hooks_before_insert = Edge._session_hooks_before_insert

hooks_before_update = Edge._session_hooks_before_update

hooks_before_delete = Edge._session_hooks_before_delete

if CACHE_CASES:
hooks_before_insert = Edge._session_hooks_before_insert + [
cache_related_cases_on_insert,
]

hooks_before_update = Edge._session_hooks_before_update + [
cache_related_cases_on_update,
]

hooks_before_delete = Edge._session_hooks_before_delete + [
cache_related_cases_on_delete,
]

hooks_before_delete = Edge._session_hooks_before_delete + [
cache_related_cases_on_delete,
]

cls = type(name, (Edge,), {
'__label__': label,
Expand Down Expand Up @@ -568,7 +579,7 @@ def load_edges():
or src_cls.label in ['annotation']
)

if not cache_case:
if not cache_case or not CACHE_CASES:
continue

link = {
Expand Down
6 changes: 6 additions & 0 deletions gdcdatamodel/models/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@

from cdisutils.log import get_logger
from psqlgraph import Node, Edge
from gdcdictionary import gdcdictionary

logger = get_logger('gdcdatamodel')

CACHE_CASES = (
True if not hasattr(gdcdictionary, 'settings')
else gdcdictionary.settings.get('enable_case_cache', True)
)

#: This variable contains the link name for the case shortcut
#: association proxy
RELATED_CASES_LINK_NAME = '_related_cases'
Expand Down