Commit 87394841 authored by Julien Muchembled's avatar Julien Muchembled

Fix unindexObject performance by grouping them

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37688 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 55bbf2e7
...@@ -769,6 +769,13 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject): ...@@ -769,6 +769,13 @@ class CatalogTool (UniqueObject, ZCatalog, CMFCoreCatalogTool, ActiveObject):
else: else:
super(CatalogTool, self).catalogObjectList(object_list, *args, **kw) super(CatalogTool, self).catalogObjectList(object_list, *args, **kw)
security.declarePrivate('uncatalogObjectList')
def uncatalogObjectList(self, message_list):
"""Uncatalog a list of objects"""
for obj, args, kw in message_list:
self.unindexObject(*args, **kw)
del message_list[:]
security.declarePrivate('unindexObject') security.declarePrivate('unindexObject')
def unindexObject(self, object=None, path=None, uid=None,sql_catalog_id=None): def unindexObject(self, object=None, path=None, uid=None,sql_catalog_id=None):
""" """
......
...@@ -375,14 +375,12 @@ class CopyContainer: ...@@ -375,14 +375,12 @@ class CopyContainer:
catalog.beforeUnindexObject(None,path=path,uid=uid) catalog.beforeUnindexObject(None,path=path,uid=uid)
# Then start activity in order to remove lines in catalog, # Then start activity in order to remove lines in catalog,
# sql wich generate locks # sql wich generate locks
if path is None:
path = self.getPath()
# - serialization_tag is used in order to prevent unindexation to # - serialization_tag is used in order to prevent unindexation to
# happen before/in parallel with reindexations of the same object. # happen before/in parallel with reindexations of the same object.
catalog.activate(activity='SQLQueue', catalog.activate(activity='SQLQueue',
tag='%s' % uid, tag='%s' % uid,
serialization_tag=self.getRootDocumentPath()).unindexObject(None, group_method_id='portal_catalog/uncatalogObjectList',
path=path,uid=uid) serialization_tag=self.getRootDocumentPath()).unindexObject(uid=uid)
security.declareProtected(Permissions.ModifyPortalContent, 'moveObject') security.declareProtected(Permissions.ModifyPortalContent, 'moveObject')
def moveObject(self, idxs=None): def moveObject(self, idxs=None):
......
...@@ -31,6 +31,7 @@ import transaction ...@@ -31,6 +31,7 @@ import transaction
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
#from AccessControl.SecurityManagement import newSecurityManager #from AccessControl.SecurityManagement import newSecurityManager
from Products.CMFActivity.ActivityTool import ActivityTool
from Products.CMFActivity.Errors import ActivityPendingError from Products.CMFActivity.Errors import ActivityPendingError
class TestCopySupport(ERP5TypeTestCase): class TestCopySupport(ERP5TypeTestCase):
...@@ -100,13 +101,49 @@ class TestCopySupport(ERP5TypeTestCase): ...@@ -100,13 +101,49 @@ class TestCopySupport(ERP5TypeTestCase):
# Currently, the test passes only because ActivityTool.distribute always # Currently, the test passes only because ActivityTool.distribute always
# iterates on queues in the same order: SQLQueue before SQLDict. # iterates on queues in the same order: SQLQueue before SQLDict.
# If Python returned dictionary values in a different order, # If Python returned dictionary values in a different order,
# reindex activities fail with the following error: # reindex activities would fail with the following error:
# uid of <Products.ERP5Catalog.CatalogTool.IndexableObjectWrapper for # uid of <Products.ERP5Catalog.CatalogTool.IndexableObjectWrapper for
# /erp5/person_module/1/old_address> is 599L and is already assigned # /erp5/person_module/1/old_address> is 599L and is already assigned
# to deleted in catalog !!! This can be fatal. # to deleted in catalog !!! This can be fatal.
# This test would also fail if SQLDict was used for 'unindexObject'. # This test would also fail if SQLDict was used for 'unindexObject'.
self.tic() self.tic()
def test_03_unindexObjectGrouping(self):
person = self.portal.person_module.newContent(portal_type='Person',
address_city='Lille',
email_text='foo@bar.com')
transaction.commit()
self.tic()
search_catalog = self.portal.portal_catalog.unrestrictedSearchResults
uid_list = [person.getUid(),
person.default_address.getUid(),
person.default_email.getUid()]
uid_list.sort()
self.assertEqual(len(search_catalog(uid=uid_list)), len(uid_list))
self.portal.person_module._delObject(person.getId())
del person
transaction.commit()
self.assertEqual(len(search_catalog(uid=uid_list)), len(uid_list))
activity_tool = self.portal.portal_activities
self.assertEqual(len(activity_tool.getMessageList()), len(uid_list))
ActivityTool_invokeGroup = ActivityTool.invokeGroup
invokeGroup_list = []
def invokeGroup(self, method_id, message_list, activity):
invokeGroup_list.extend((method_id,
sorted(m.kw.get('uid') for m in message_list),
activity))
return ActivityTool_invokeGroup(self, method_id, message_list, activity)
try:
ActivityTool.invokeGroup = invokeGroup
self.tic()
finally:
ActivityTool.invokeGroup = ActivityTool_invokeGroup
self.assertEqual(invokeGroup_list,
['portal_catalog/uncatalogObjectList', uid_list, 'SQLQueue'])
self.assertEqual(len(search_catalog(uid=uid_list)), 0)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCopySupport)) suite.addTest(unittest.makeSuite(TestCopySupport))
......
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