[Erp5-report] r15573 - /erp5/trunk/products/ERP5/Document/Predicate.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Aug 8 23:27:30 CEST 2007
Author: yo
Date: Wed Aug 8 23:27:30 2007
New Revision: 15573
URL: http://svn.erp5.org?rev=15573&view=rev
Log:
Enable the read-only transaction cache temporarily when checking category membership, because this is guaranteed not to change categories. This change improves the performance significantly when there are many membership criterion categories.
Modified:
erp5/trunk/products/ERP5/Document/Predicate.py
Modified: erp5/trunk/products/ERP5/Document/Predicate.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/Predicate.py?rev=15573&r1=15572&r2=15573&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/Predicate.py (original)
+++ erp5/trunk/products/ERP5/Document/Predicate.py Wed Aug 8 23:27:30 2007
@@ -37,6 +37,7 @@
from Products.ERP5Type.Document import newTempBase
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Utils import convertToUpperCase
+from Products.ERP5Type.Cache import getReadOnlyTransactionCache, enableReadOnlyTransactionCache, disableReadOnlyTransactionCache
from zLOG import LOG
@@ -132,23 +133,34 @@
membership_criterion_category_list if x.split('/', 1)[0] in \
tested_base_category_list]
- for c in membership_criterion_category_list:
- bc = c.split('/', 1)[0]
- if (bc not in tested_base_category) and \
- (bc in multimembership_criterion_base_category_list):
- tested_base_category[bc] = 1
- elif (bc not in tested_base_category) and \
- (bc in membership_criterion_base_category_list):
- tested_base_category[bc] = 0
- if (bc in multimembership_criterion_base_category_list):
- tested_base_category[bc] = tested_base_category[bc] and \
- context.isMemberOf(c)
+ # Test category memberships. Enable the read-only transaction cache
+ # 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)
+ try:
+ if not enabled:
+ enableReadOnlyTransactionCache(self)
+ for c in membership_criterion_category_list:
+ bc = c.split('/', 1)[0]
+ if (bc not in tested_base_category) and \
+ (bc in multimembership_criterion_base_category_list):
+ tested_base_category[bc] = 1
+ elif (bc not in tested_base_category) and \
+ (bc in membership_criterion_base_category_list):
+ tested_base_category[bc] = 0
+ if (bc in multimembership_criterion_base_category_list):
+ tested_base_category[bc] = tested_base_category[bc] and \
+ context.isMemberOf(c)
# LOG('predicate test', 0,
# '%s after multi membership to %s' % \
# (tested_base_category[bc], c))
- elif (bc in membership_criterion_base_category_list):
- tested_base_category[bc] = tested_base_category[bc] or \
- context.isMemberOf(c)
+ elif (bc in membership_criterion_base_category_list):
+ tested_base_category[bc] = tested_base_category[bc] or \
+ context.isMemberOf(c)
+ finally:
+ if not enabled:
+ disableReadOnlyTransactionCache(self)
# LOG('predicate test', 0,
# '%s after single membership to %s' % \
More information about the Erp5-report
mailing list