Commit 80b0f8f7 authored by Julien Muchembled's avatar Julien Muchembled

Same for *ReadOnlyTransactionCache

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38367 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 22cee6c5
...@@ -209,7 +209,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -209,7 +209,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
Returns a Category object from a given category url Returns a Category object from a given category url
and optionnal base category id and optionnal base category id
""" """
cache = getReadOnlyTransactionCache(self) cache = getReadOnlyTransactionCache()
if cache is not None: if cache is not None:
key = ('getCategoryValue', relative_url, base_category) key = ('getCategoryValue', relative_url, base_category)
try: try:
...@@ -848,7 +848,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -848,7 +848,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
'getSingleCategoryAcquiredMembershipList' ) 'getSingleCategoryAcquiredMembershipList' )
def getSingleCategoryAcquiredMembershipList(self, context, base_category, base=0, def getSingleCategoryAcquiredMembershipList(self, context, base_category, base=0,
spec=(), filter=None, acquired_object_dict = None, **kw ): spec=(), filter=None, acquired_object_dict = None, **kw ):
cache = getReadOnlyTransactionCache(self) cache = getReadOnlyTransactionCache()
if cache is not None: if cache is not None:
key = ('getSingleCategoryAcquiredMembershipList', context.getPhysicalPath(), base_category, base, spec, key = ('getSingleCategoryAcquiredMembershipList', context.getPhysicalPath(), base_category, base, spec,
filter, str(kw)) filter, str(kw))
...@@ -1627,7 +1627,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1627,7 +1627,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
if not isinstance(relative_url, str): if not isinstance(relative_url, str):
# Handle parent base category is a special way # Handle parent base category is a special way
return relative_url return relative_url
cache = getReadOnlyTransactionCache(self) cache = getReadOnlyTransactionCache()
if cache is not None: if cache is not None:
cache_key = ('resolveCategory', relative_url) cache_key = ('resolveCategory', relative_url)
try: try:
......
...@@ -97,10 +97,10 @@ class ContributionPredicate(Predicate, XMLObject): ...@@ -97,10 +97,10 @@ class ContributionPredicate(Predicate, XMLObject):
# temporarily, if not enabled, because this part is strictly read-only, # temporarily, if not enabled, because this part is strictly read-only,
# and context.isMemberOf is very expensive, when the category list has # and context.isMemberOf is very expensive, when the category list has
# many items. # many items.
enabled = (getReadOnlyTransactionCache(self) is not None) enabled = getReadOnlyTransactionCache() is not None
try: try:
if not enabled: if not enabled:
enableReadOnlyTransactionCache(self) enableReadOnlyTransactionCache()
for c in membership_criterion_category_list: for c in membership_criterion_category_list:
bc = c.split('/', 1)[0] bc = c.split('/', 1)[0]
if (bc not in tested_base_category) and \ if (bc not in tested_base_category) and \
...@@ -117,7 +117,7 @@ class ContributionPredicate(Predicate, XMLObject): ...@@ -117,7 +117,7 @@ class ContributionPredicate(Predicate, XMLObject):
context.isMemberOf(c) context.isMemberOf(c)
finally: finally:
if not enabled: if not enabled:
disableReadOnlyTransactionCache(self) disableReadOnlyTransactionCache()
result = result and (0 not in tested_base_category.values()) result = result and (0 not in tested_base_category.values())
# Test method calls # Test method calls
......
...@@ -152,10 +152,10 @@ class Predicate(XMLObject): ...@@ -152,10 +152,10 @@ class Predicate(XMLObject):
# temporarily, if not enabled, because this part is strictly read-only, # temporarily, if not enabled, because this part is strictly read-only,
# and context.isMemberOf is very expensive, when the category list has # and context.isMemberOf is very expensive, when the category list has
# many items. # many items.
enabled = (getReadOnlyTransactionCache(self) is not None) enabled = getReadOnlyTransactionCache() is not None
try: try:
if not enabled: if not enabled:
enableReadOnlyTransactionCache(self) enableReadOnlyTransactionCache()
for c in membership_criterion_category_list: for c in membership_criterion_category_list:
bc = c.split('/', 1)[0] bc = c.split('/', 1)[0]
if (bc not in tested_base_category) and \ if (bc not in tested_base_category) and \
...@@ -177,7 +177,7 @@ class Predicate(XMLObject): ...@@ -177,7 +177,7 @@ class Predicate(XMLObject):
strict_membership=strict_membership) strict_membership=strict_membership)
finally: finally:
if not enabled: if not enabled:
disableReadOnlyTransactionCache(self) disableReadOnlyTransactionCache()
# LOG('predicate test', 0, # LOG('predicate test', 0,
# '%s after single membership to %s' % \ # '%s after single membership to %s' % \
......
...@@ -232,7 +232,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin): ...@@ -232,7 +232,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
portal type dependent script: portal type dependent script:
WebSection_getDefaultDocumentValue WebSection_getDefaultDocumentValue
""" """
cache = getReadOnlyTransactionCache(self) cache = getReadOnlyTransactionCache()
if cache is not None: if cache is not None:
key = ('getDefaultDocumentValue', self) key = ('getDefaultDocumentValue', self)
try: try:
...@@ -264,7 +264,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin): ...@@ -264,7 +264,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
portal type dependent script: portal type dependent script:
WebSection_getDocumentValueList WebSection_getDocumentValueList
""" """
cache = getReadOnlyTransactionCache(self) cache = getReadOnlyTransactionCache()
if cache is not None: if cache is not None:
key = ('getDocumentValueList', self) + tuple(kw.items()) key = ('getDocumentValueList', self) + tuple(kw.items())
try: try:
...@@ -296,7 +296,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin): ...@@ -296,7 +296,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
portal type dependent script: portal type dependent script:
WebSection_getPermanentURL WebSection_getPermanentURL
""" """
cache = getReadOnlyTransactionCache(self) cache = getReadOnlyTransactionCache()
if cache is not None: if cache is not None:
key = ('getPermanentURL', self, document.getPath()) key = ('getPermanentURL', self, document.getPath())
try: try:
...@@ -325,7 +325,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin): ...@@ -325,7 +325,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
""" """
if document is None: if document is None:
document = self document = self
cache = getReadOnlyTransactionCache(self) cache = getReadOnlyTransactionCache()
if cache is not None: if cache is not None:
key = ('getBreadcrumbItemList', self, document.getPath()) key = ('getBreadcrumbItemList', self, document.getPath())
try: try:
...@@ -370,7 +370,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin): ...@@ -370,7 +370,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
portal type dependent script: portal type dependent script:
WebSection_getSiteMapTree WebSection_getSiteMapTree
""" """
cache = getReadOnlyTransactionCache(self) cache = getReadOnlyTransactionCache()
if cache is not None: if cache is not None:
key = ('getSiteMapTree', self) + tuple(kw.items()) key = ('getSiteMapTree', self) + tuple(kw.items())
try: try:
......
...@@ -71,7 +71,7 @@ class BaseExtensibleTraversableMixin(ExtensibleTraversableMixIn): ...@@ -71,7 +71,7 @@ class BaseExtensibleTraversableMixin(ExtensibleTraversableMixIn):
def _forceIdentification(self, request): def _forceIdentification(self, request):
# force identification (usable for extensible content) # force identification (usable for extensible content)
cache = getReadOnlyTransactionCache(self) cache = getReadOnlyTransactionCache()
if cache is not None: if cache is not None:
key = ('__bobo_traverse__', self, 'user') key = ('__bobo_traverse__', self, 'user')
try: try:
......
...@@ -32,7 +32,7 @@ from time import time ...@@ -32,7 +32,7 @@ from time import time
from AccessControl.SecurityInfo import allow_class from AccessControl.SecurityInfo import allow_class
from CachePlugins.BaseCache import CachedMethodError from CachePlugins.BaseCache import CachedMethodError
from zLOG import LOG, WARNING from zLOG import LOG, WARNING
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable from Products.ERP5Type.TransactionalVariable import getTransactionalVariable, _MARKER
from Products.ERP5Type.Utils import simple_decorator from Products.ERP5Type.Utils import simple_decorator
from warnings import warn from warnings import warn
...@@ -235,29 +235,20 @@ allow_class(CachingMethod) ...@@ -235,29 +235,20 @@ allow_class(CachingMethod)
# TransactionCache is a cache per transaction. The purpose of this cache is # TransactionCache is a cache per transaction. The purpose of this cache is
# to accelerate some heavy read-only operations. Note that this must not be # to accelerate some heavy read-only operations. Note that this must not be
# enabled when a transaction may modify ZODB objects. # enabled when a transaction may modify ZODB objects.
def getReadOnlyTransactionCache(context): def getReadOnlyTransactionCache(context=_MARKER):
"""Get the transaction cache. """Get the transaction cache.
""" """
tv = getTransactionalVariable(context) return getTransactionalVariable(context).get('read_only_transaction_cache')
try:
return tv['read_only_transaction_cache']
except KeyError:
return None
def enableReadOnlyTransactionCache(context): def enableReadOnlyTransactionCache(context=_MARKER):
"""Enable the transaction cache. """Enable the transaction cache.
""" """
tv = getTransactionalVariable(context) getTransactionalVariable(context)['read_only_transaction_cache'] = {}
tv['read_only_transaction_cache'] = {}
def disableReadOnlyTransactionCache(context): def disableReadOnlyTransactionCache(context=_MARKER):
"""Disable the transaction cache. """Disable the transaction cache.
""" """
tv = getTransactionalVariable(context) getTransactionalVariable(context).pop('read_only_transaction_cache', None)
try:
del tv['read_only_transaction_cache']
except KeyError:
pass
######################################################## ########################################################
## Old global cache functions ## ## Old global cache functions ##
......
...@@ -1310,9 +1310,8 @@ def createExpressionContext(object, portal=None): ...@@ -1310,9 +1310,8 @@ def createExpressionContext(object, portal=None):
return ec return ec
def getExistingBaseCategoryList(portal, base_cat_list): def getExistingBaseCategoryList(portal, base_cat_list):
cache = getReadOnlyTransactionCache(portal) cache = getReadOnlyTransactionCache()
if cache is None: if cache is None:
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
cache = getTransactionalVariable() cache = getTransactionalVariable()
category_tool = portal.portal_categories category_tool = portal.portal_categories
new_base_cat_list = [] new_base_cat_list = []
......
...@@ -1407,7 +1407,7 @@ class Catalog(Folder, ...@@ -1407,7 +1407,7 @@ class Catalog(Folder,
try: try:
if not disable_cache: if not disable_cache:
enableReadOnlyTransactionCache(self) enableReadOnlyTransactionCache()
filter_dict = self.filter_dict filter_dict = self.filter_dict
catalogged_object_list_cache = {} catalogged_object_list_cache = {}
...@@ -1531,7 +1531,7 @@ class Catalog(Folder, ...@@ -1531,7 +1531,7 @@ class Catalog(Folder,
raise raise
finally: finally:
if not disable_cache: if not disable_cache:
disableReadOnlyTransactionCache(self) disableReadOnlyTransactionCache()
if psyco is not None: if psyco is not None:
psyco.bind(_catalogObjectList) psyco.bind(_catalogObjectList)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment