Commit 76213b54 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

make zsqlbrain's activate() return an ActiveWrapper object without calling getObject().

With this change, code like the following will use much less memory.

  for i in portal_catalog(...):
    i.activate().method()
Signed-off-by: Vincent Pelletier's avatarVincent Pelletier <vincent@nexedi.com>
parent 6c3fa4f1
......@@ -3442,6 +3442,16 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
).getTitle()
self.tic()
def test_activateOnZsqlBrain(self):
portal = self.getPortal()
organisation_module = self.getOrganisationModule()
if not organisation_module.hasContent(self.company_id):
organisation_module.newContent(id=self.company_id)
self.tic()
organisation = organisation_module.searchFolder(id=self.company_id)[0]
organisation.activate().getTitle()
self.tic()
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCMFActivity))
......
......@@ -23,6 +23,11 @@ from AccessControl.SecurityInfo import allow_class
from zLOG import LOG, WARNING
try:
from Products.CMFActivity.ActiveObject import DEFAULT_ACTIVITY
except ImportError:
DEFAULT_ACTIVITY = None
_MARKER = []
class ZSQLBrain(Acquisition.Implicit):
......@@ -120,6 +125,35 @@ class ZSQLBrain(Acquisition.Implicit):
except:
pass
# If CMFActivity is available, we add ZSQLBrain.activate() that does
# not call getObject() for better performance and less memory usage.
if DEFAULT_ACTIVITY is not None:
def activate(self, activity=DEFAULT_ACTIVITY, active_process=None,
activate_kw=None, **kw):
"""
This method returns an ActiveWrapper without calling getObject().
See CMFActivity.ActiveObject.activate() for the detail of API.
"""
try:
activity_tool = self.aq_parent.getPortalObject().portal_activities
except AttributeError:
return self # Do nothing if no portal_activities
# here we cannot have local default_activate_parameter because
# we don't want to access the object. if we really need local
# one, we can just call like brain.getObject().activate()
# instead.
new_kw = activity_tool.getDefaultActivateParameterDict(inherit_placeless=False)
if activate_kw:
new_kw.update(activate_kw)
new_kw.update(kw)
# activate returns an ActiveWrapper
# a queue can be provided as well as extra parameters
# which can be used for example to define deferred tasks
return activity_tool.activateObject(
self.getPath(), activity, active_process, **new_kw)
allow_class(ZSQLBrain)
class ZSQLBrainNoObject(ZSQLBrain):
......
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