From f8f6737473a35f470cc4d30a9aaa27455f8ce78d Mon Sep 17 00:00:00 2001 From: Yusei Tahara Date: Tue, 20 Mar 2018 17:38:21 +0100 Subject: [PATCH] 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. --- product/ERP5Type/Base.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/product/ERP5Type/Base.py b/product/ERP5Type/Base.py index eb6fc96f10d..bbc234d0843 100644 --- a/product/ERP5Type/Base.py +++ b/product/ERP5Type/Base.py @@ -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) - if getattr(aq_base(self), 'CreationDate', None) is not None: - return asDate(self.CreationDate()) + result = history[0].get('time', None) + if result is None: + 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 security.declareProtected(Permissions.AccessContentsInformation, 'getModificationDate') -- 2.30.9