diff --git a/gdcdatamodel/models/__init__.py b/gdcdatamodel/models/__init__.py index ae945419..ea28903d 100644 --- a/gdcdatamodel/models/__init__.py +++ b/gdcdatamodel/models/__init__.py @@ -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, @@ -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( @@ -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, @@ -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 = { diff --git a/gdcdatamodel/models/caching.py b/gdcdatamodel/models/caching.py index d73f6f52..8efaa9af 100644 --- a/gdcdatamodel/models/caching.py +++ b/gdcdatamodel/models/caching.py @@ -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'