Commit 03890b50 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 29dc4119
...@@ -3131,12 +3131,16 @@ class Base( CopyContainer, ...@@ -3131,12 +3131,16 @@ class Base( CopyContainer,
""" """
Returns the creation date of the document based on workflow information 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 # Check if edit_workflow defined
portal_workflow = self.getPortalObject().portal_workflow portal_workflow = self.getPortalObject().portal_workflow
wf = portal_workflow.getWorkflowById('edit_workflow') wf = portal_workflow.getWorkflowById('edit_workflow')
wf_list = portal_workflow.getWorkflowsFor(self) wf_list = portal_workflow.getWorkflowsFor(self)
if wf is not None: if wf is not None:
wf_list = [wf] + wf_list wf_list = [wf] + wf_list
result = None
for wf in wf_list: for wf in wf_list:
try: try:
history = wf.getInfoFor(self, 'history', None) history = wf.getInfoFor(self, 'history', None)
...@@ -3144,9 +3148,13 @@ class Base( CopyContainer, ...@@ -3144,9 +3148,13 @@ class Base( CopyContainer,
history = None history = None
if history is not None and len(history): if history is not None and len(history):
# Then get the first line of edit_workflow # Then get the first line of edit_workflow
return history[0].get('time', None) result = history[0].get('time', None)
if getattr(aq_base(self), 'CreationDate', None) is not None: if result is None:
return asDate(self.CreationDate()) if getattr(aq_base(self), 'CreationDate', None) is not None:
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 return None # JPS-XXX - try to find a way to return a creation date instead of None
security.declareProtected(Permissions.AccessContentsInformation, 'getModificationDate') 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