Commit 6defa865 authored by Rafael Monnerat's avatar Rafael Monnerat

Implement faster getCreationDate response on large workflow lists

parent 16f740ac
......@@ -3184,19 +3184,23 @@ class Base( CopyContainer,
Returns the creation date of the document based on workflow information
"""
# Check if edit_workflow defined
portal_workflow = self.getPortalObject().portal_workflow
wf = portal_workflow.getWorkflowById('edit_workflow')
wf_list = portal_workflow.getWorkflowsFor(self)
if wf is not None:
wf_list = [wf] + wf_list
for wf in wf_list:
try:
history = wf.getInfoFor(self, 'history', None)
except KeyError:
history = None
if history is not None and len(history):
# Then get the first line of edit_workflow
return history[0].get('time', None)
try:
history_list = aq_base(self).workflow_history
except AttributeError:
pass
else:
candidate = None
for wf_id, history in history_list.iteritems():
try:
if wf_id == "edit_workflow":
return history[0]['time']
elif candidate is None:
candidate = history[0]['time']
except (IndexError, KeyError, TypeError):
pass
if candidate is not None:
return candate
if getattr(aq_base(self), 'CreationDate', None) is not None:
return asDate(self.CreationDate())
return None # JPS-XXX - try to find a way to return a creation date instead of None
......
......@@ -722,7 +722,7 @@ def WorkflowTool_refreshWorklistCache(self):
security.declareProtected(Permissions.ManagePortal, 'refreshWorklistCache')
WorkflowTool.refreshWorklistCache = WorkflowTool_refreshWorklistCache
class WorkflowHistoryList(Persistent):
class WorkflowHistoryBucketList(Persistent):
_bucket_size = 16
def __init__(self, iterable=None, prev=None):
......@@ -748,6 +748,13 @@ class WorkflowHistoryList(Persistent):
if index < 0:
# XXX this implementation is not so good, but rarely used.
index += len(self)
elif index <= self._bucket_size:
if getattr(self,'_first', None):
# Speed up access to the first elements
return self._first._slots[index]
if self._prev is not None and getattr(self, "_init_first", None):
self._init_first()
return self._first._slots[index]
iterator = self.__iter__()
for i in xrange(index):
iterator.next()
......@@ -806,6 +813,42 @@ class WorkflowHistoryList(Persistent):
self._prev = self.__class__(self._slots, prev=self._prev)
self._slots = [value]
class WorkflowHistoryList(WorkflowHistoryBucketList):
def __init__(self, iterable=None, prev=None):
WorkflowHistoryBucketList.__init__(self, iterable, prev)
self._first = None
def _init_first(self):
if getattr(self,'_first', None) is None:
# Handle migration of old workflow history
bucket = self._prev
while bucket._prev is not None:
bucket = bucket._prev
self._first = bucket
self._p_changed = 1
def append(self, value):
if len(self._slots) < self._bucket_size:
self._slots.append(value)
self._p_changed = 1
else:
self._prev = WorkflowHistoryBucketList(
self._slots, prev=self._prev)
self._slots = [value]
self._init_first()
def __setstate__(self, state):
if len(state) == 2:
self._prev, self._slots = state
self._first = None
else:
self._prev, self._slots, self._first = state
def __getstate__(self):
return (self._prev, self._slots, getattr(self, "_first", None))
def WorkflowTool_setStatusOf(self, wf_id, ob, status):
""" Append an entry to the workflow history.
......
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