Commit 77668397 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Enable the read-only transaction cache temporarily when checking category...

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.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15573 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 4d7a216b
...@@ -37,6 +37,7 @@ from Products.ERP5Type.Core.Folder import Folder ...@@ -37,6 +37,7 @@ from Products.ERP5Type.Core.Folder import Folder
from Products.ERP5Type.Document import newTempBase from Products.ERP5Type.Document import newTempBase
from Products.ERP5Type.XMLObject import XMLObject from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5Type.Utils import convertToUpperCase from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.Cache import getReadOnlyTransactionCache, enableReadOnlyTransactionCache, disableReadOnlyTransactionCache
from zLOG import LOG from zLOG import LOG
...@@ -132,23 +133,34 @@ class Predicate(XMLObject, Folder): ...@@ -132,23 +133,34 @@ class Predicate(XMLObject, Folder):
membership_criterion_category_list if x.split('/', 1)[0] in \ membership_criterion_category_list if x.split('/', 1)[0] in \
tested_base_category_list] tested_base_category_list]
for c in membership_criterion_category_list: # Test category memberships. Enable the read-only transaction cache
bc = c.split('/', 1)[0] # temporarily, if not enabled, because this part is strictly read-only,
if (bc not in tested_base_category) and \ # and context.isMemberOf is very expensive, when the category list has
(bc in multimembership_criterion_base_category_list): # many items.
tested_base_category[bc] = 1 enabled = (getReadOnlyTransactionCache(self) is not None)
elif (bc not in tested_base_category) and \ try:
(bc in membership_criterion_base_category_list): if not enabled:
tested_base_category[bc] = 0 enableReadOnlyTransactionCache(self)
if (bc in multimembership_criterion_base_category_list): for c in membership_criterion_category_list:
tested_base_category[bc] = tested_base_category[bc] and \ bc = c.split('/', 1)[0]
context.isMemberOf(c) 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, # LOG('predicate test', 0,
# '%s after multi membership to %s' % \ # '%s after multi membership to %s' % \
# (tested_base_category[bc], c)) # (tested_base_category[bc], c))
elif (bc in membership_criterion_base_category_list): elif (bc in membership_criterion_base_category_list):
tested_base_category[bc] = tested_base_category[bc] or \ tested_base_category[bc] = tested_base_category[bc] or \
context.isMemberOf(c) context.isMemberOf(c)
finally:
if not enabled:
disableReadOnlyTransactionCache(self)
# LOG('predicate test', 0, # LOG('predicate test', 0,
# '%s after single membership to %s' % \ # '%s after single membership to %s' % \
......
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