Commit f8f67374 authored by Yusei Tahara's avatar Yusei Tahara

ERP5Type/Base.py: Store a result of getCreationDate and returns it next time....

ERP5Type/Base.py: Store a result of getCreationDate and returns it next time. Otherwise if there is a very long history, getCreationDate becomes slow because of append-optimized data structure of WorkflowHistoryList.
parent 6c26f831
......@@ -3131,12 +3131,16 @@ class Base( CopyContainer,
"""
Returns the creation date of the document based on workflow information
"""
if getattr(self, '_creation_date', None) is not None:
return DateTime(self._creation_date)
# 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
result = None
for wf in wf_list:
try:
history = wf.getInfoFor(self, 'history', None)
......@@ -3144,9 +3148,13 @@ class Base( CopyContainer,
history = None
if history is not None and len(history):
# Then get the first line of edit_workflow
return history[0].get('time', None)
result = history[0].get('time', None)
if result is None:
if getattr(aq_base(self), 'CreationDate', None) is not None:
return asDate(self.CreationDate())
result = asDate(self.CreationDate())
if result is not None:
self._creation_date = DateTime(result)
return result
return None # JPS-XXX - try to find a way to return a creation date instead of None
security.declareProtected(Permissions.AccessContentsInformation, 'getModificationDate')
......
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