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,6 +133,14 @@ class Predicate(XMLObject, Folder): ...@@ -132,6 +133,14 @@ 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]
# 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: 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 \
...@@ -149,6 +158,9 @@ class Predicate(XMLObject, Folder): ...@@ -149,6 +158,9 @@ class Predicate(XMLObject, Folder):
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