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 ):
Returns a Category object from a given category url
and optionnal base category id
"""
cache = getReadOnlyTransactionCache(self)
cache = getReadOnlyTransactionCache()
if cache is not None:
key = ('getCategoryValue', relative_url, base_category)
try:
......@@ -848,7 +848,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
'getSingleCategoryAcquiredMembershipList' )
def getSingleCategoryAcquiredMembershipList(self, context, base_category, base=0,
spec=(), filter=None, acquired_object_dict = None, **kw ):
cache = getReadOnlyTransactionCache(self)
cache = getReadOnlyTransactionCache()
if cache is not None:
key = ('getSingleCategoryAcquiredMembershipList', context.getPhysicalPath(), base_category, base, spec,
filter, str(kw))
......@@ -1627,7 +1627,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
if not isinstance(relative_url, str):
# Handle parent base category is a special way
return relative_url
cache = getReadOnlyTransactionCache(self)
cache = getReadOnlyTransactionCache()
if cache is not None:
cache_key = ('resolveCategory', relative_url)
try:
......
......@@ -97,10 +97,10 @@ class ContributionPredicate(Predicate, XMLObject):
# temporarily, if not enabled, because this part is strictly read-only,
# and context.isMemberOf is very expensive, when the category list has
# many items.
enabled = (getReadOnlyTransactionCache(self) is not None)
enabled = getReadOnlyTransactionCache() is not None
try:
if not enabled:
enableReadOnlyTransactionCache(self)
enableReadOnlyTransactionCache()
for c in membership_criterion_category_list:
bc = c.split('/', 1)[0]
if (bc not in tested_base_category) and \
......@@ -117,7 +117,7 @@ class ContributionPredicate(Predicate, XMLObject):
context.isMemberOf(c)
finally:
if not enabled:
disableReadOnlyTransactionCache(self)
disableReadOnlyTransactionCache()
result = result and (0 not in tested_base_category.values())
# Test method calls
......
......@@ -152,10 +152,10 @@ class Predicate(XMLObject):
# temporarily, if not enabled, because this part is strictly read-only,
# and context.isMemberOf is very expensive, when the category list has
# many items.
enabled = (getReadOnlyTransactionCache(self) is not None)
enabled = getReadOnlyTransactionCache() is not None
try:
if not enabled:
enableReadOnlyTransactionCache(self)
enableReadOnlyTransactionCache()
for c in membership_criterion_category_list:
bc = c.split('/', 1)[0]
if (bc not in tested_base_category) and \
......@@ -177,7 +177,7 @@ class Predicate(XMLObject):
strict_membership=strict_membership)
finally:
if not enabled:
disableReadOnlyTransactionCache(self)
disableReadOnlyTransactionCache()
# LOG('predicate test', 0,
# '%s after single membership to %s' % \
......
......@@ -232,7 +232,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
portal type dependent script:
WebSection_getDefaultDocumentValue
"""
cache = getReadOnlyTransactionCache(self)
cache = getReadOnlyTransactionCache()
if cache is not None:
key = ('getDefaultDocumentValue', self)
try:
......@@ -264,7 +264,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
portal type dependent script:
WebSection_getDocumentValueList
"""
cache = getReadOnlyTransactionCache(self)
cache = getReadOnlyTransactionCache()
if cache is not None:
key = ('getDocumentValueList', self) + tuple(kw.items())
try:
......@@ -296,7 +296,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
portal type dependent script:
WebSection_getPermanentURL
"""
cache = getReadOnlyTransactionCache(self)
cache = getReadOnlyTransactionCache()
if cache is not None:
key = ('getPermanentURL', self, document.getPath())
try:
......@@ -325,7 +325,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
"""
if document is None:
document = self
cache = getReadOnlyTransactionCache(self)
cache = getReadOnlyTransactionCache()
if cache is not None:
key = ('getBreadcrumbItemList', self, document.getPath())
try:
......@@ -370,7 +370,7 @@ class WebSection(Domain, DocumentExtensibleTraversableMixin):
portal type dependent script:
WebSection_getSiteMapTree
"""
cache = getReadOnlyTransactionCache(self)
cache = getReadOnlyTransactionCache()
if cache is not None:
key = ('getSiteMapTree', self) + tuple(kw.items())
try:
......
......@@ -71,7 +71,7 @@ class BaseExtensibleTraversableMixin(ExtensibleTraversableMixIn):
def _forceIdentification(self, request):
# force identification (usable for extensible content)
cache = getReadOnlyTransactionCache(self)
cache = getReadOnlyTransactionCache()
if cache is not None:
key = ('__bobo_traverse__', self, 'user')
try:
......
......@@ -32,7 +32,7 @@ from time import time
from AccessControl.SecurityInfo import allow_class
from CachePlugins.BaseCache import CachedMethodError
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 warnings import warn
......@@ -235,29 +235,20 @@ allow_class(CachingMethod)
# 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
# enabled when a transaction may modify ZODB objects.
def getReadOnlyTransactionCache(context):
def getReadOnlyTransactionCache(context=_MARKER):
"""Get the transaction cache.
"""
tv = getTransactionalVariable(context)
try:
return tv['read_only_transaction_cache']
except KeyError:
return None
return getTransactionalVariable(context).get('read_only_transaction_cache')
def enableReadOnlyTransactionCache(context):
def enableReadOnlyTransactionCache(context=_MARKER):
"""Enable the transaction cache.
"""
tv = getTransactionalVariable(context)
tv['read_only_transaction_cache'] = {}
getTransactionalVariable(context)['read_only_transaction_cache'] = {}
def disableReadOnlyTransactionCache(context):
def disableReadOnlyTransactionCache(context=_MARKER):
"""Disable the transaction cache.
"""
tv = getTransactionalVariable(context)
try:
del tv['read_only_transaction_cache']
except KeyError:
pass
getTransactionalVariable(context).pop('read_only_transaction_cache', None)
########################################################
## Old global cache functions ##
......
......@@ -1310,9 +1310,8 @@ def createExpressionContext(object, portal=None):
return ec
def getExistingBaseCategoryList(portal, base_cat_list):
cache = getReadOnlyTransactionCache(portal)
cache = getReadOnlyTransactionCache()
if cache is None:
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
cache = getTransactionalVariable()
category_tool = portal.portal_categories
new_base_cat_list = []
......
......@@ -1407,7 +1407,7 @@ class Catalog(Folder,
try:
if not disable_cache:
enableReadOnlyTransactionCache(self)
enableReadOnlyTransactionCache()
filter_dict = self.filter_dict
catalogged_object_list_cache = {}
......@@ -1531,7 +1531,7 @@ class Catalog(Folder,
raise
finally:
if not disable_cache:
disableReadOnlyTransactionCache(self)
disableReadOnlyTransactionCache()
if psyco is not None:
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