From 80b0f8f749b6c870927253c60d6a3f3d813577da Mon Sep 17 00:00:00 2001 From: Julien Muchembled <jm@nexedi.com> Date: Tue, 14 Sep 2010 13:56:32 +0000 Subject: [PATCH] Same for *ReadOnlyTransactionCache git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38367 20353a03-c40f-0410-a6d1-a30d3c3de9de --- product/CMFCategory/CategoryTool.py | 6 ++--- .../ERP5/Document/ContributionPredicate.py | 6 ++--- product/ERP5/Document/Predicate.py | 6 ++--- product/ERP5/Document/WebSection.py | 10 ++++---- product/ERP5/mixin/extensible_traversable.py | 2 +- product/ERP5Type/Cache.py | 23 ++++++------------- product/ERP5Type/Utils.py | 3 +-- product/ZSQLCatalog/SQLCatalog.py | 4 ++-- 8 files changed, 25 insertions(+), 35 deletions(-) diff --git a/product/CMFCategory/CategoryTool.py b/product/CMFCategory/CategoryTool.py index 3793d5f19c..ed835c8d8f 100644 --- a/product/CMFCategory/CategoryTool.py +++ b/product/CMFCategory/CategoryTool.py @@ -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: diff --git a/product/ERP5/Document/ContributionPredicate.py b/product/ERP5/Document/ContributionPredicate.py index ebe26ec984..0ed2a6ba70 100644 --- a/product/ERP5/Document/ContributionPredicate.py +++ b/product/ERP5/Document/ContributionPredicate.py @@ -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 diff --git a/product/ERP5/Document/Predicate.py b/product/ERP5/Document/Predicate.py index aac1d0c437..7c558eeee2 100644 --- a/product/ERP5/Document/Predicate.py +++ b/product/ERP5/Document/Predicate.py @@ -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' % \ diff --git a/product/ERP5/Document/WebSection.py b/product/ERP5/Document/WebSection.py index cc599c2b8a..cda106b0a4 100644 --- a/product/ERP5/Document/WebSection.py +++ b/product/ERP5/Document/WebSection.py @@ -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: diff --git a/product/ERP5/mixin/extensible_traversable.py b/product/ERP5/mixin/extensible_traversable.py index 5c262aeae1..1de3fda1e5 100644 --- a/product/ERP5/mixin/extensible_traversable.py +++ b/product/ERP5/mixin/extensible_traversable.py @@ -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: diff --git a/product/ERP5Type/Cache.py b/product/ERP5Type/Cache.py index ddeb9d617c..150293b8df 100644 --- a/product/ERP5Type/Cache.py +++ b/product/ERP5Type/Cache.py @@ -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 ## diff --git a/product/ERP5Type/Utils.py b/product/ERP5Type/Utils.py index 55341063c3..efd2264725 100644 --- a/product/ERP5Type/Utils.py +++ b/product/ERP5Type/Utils.py @@ -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 = [] diff --git a/product/ZSQLCatalog/SQLCatalog.py b/product/ZSQLCatalog/SQLCatalog.py index 14e0b89e08..fae400d0ba 100644 --- a/product/ZSQLCatalog/SQLCatalog.py +++ b/product/ZSQLCatalog/SQLCatalog.py @@ -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) -- 2.30.9