[Erp5-report] r17371 - /erp5/trunk/products/ERP5Type/patches/WorkflowTool.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Fri Nov 2 18:03:23 CET 2007
Author: vincent
Date: Fri Nov 2 18:03:23 2007
New Revision: 17371
URL: http://svn.erp5.org?rev=17371&view=rev
Log:
Optimise worklists a bit more (disabled by default since it's not well tested yet):
- Add a method to store worklists results "anonymously" (ie, without any assumption on the security of the user which will retrieve results from this table)
- Call a python method (if present) which will lookup worklists in the cache table instead of using the catalog.
Python method and ZSQLMethod used by this code will be part of a later commit.
Modified:
erp5/trunk/products/ERP5Type/patches/WorkflowTool.py
Modified: erp5/trunk/products/ERP5Type/patches/WorkflowTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/patches/WorkflowTool.py?rev=17371&r1=17370&r2=17371&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/patches/WorkflowTool.py (original)
+++ erp5/trunk/products/ERP5Type/patches/WorkflowTool.py Fri Nov 2 18:03:23 2007
@@ -27,6 +27,7 @@
from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery, NegatedQuery
from Products.CMFCore.utils import _getAuthenticatedUser
from Products.ERP5Type.Cache import CachingMethod
+from sets import ImmutableSet
def DCWorkflowDefinition_notifyWorkflowMethod(self, ob, method_id, args=None, kw=None, transition_list=None):
'''
@@ -469,7 +470,12 @@
if len(worklist_dict):
portal_url = getToolByName(self, 'portal_url')()
portal_catalog = getToolByName(self, 'portal_catalog')
- search_result = portal_catalog.unrestrictedSearchResults
+ search_result = getattr(self, "Base_getCountFromWorklistTable", None)
+ if search_result is None:
+ search_result = portal_catalog.unrestrictedSearchResults
+ select_expression_prefix = 'count(*) as %s, ' % (COUNT_COLUMN_TITLE, )
+ else:
+ select_expression_prefix = 'sum(`%s`) as %s, ' % (COUNT_COLUMN_TITLE, COUNT_COLUMN_TITLE)
getSecurityUidListAndRoleColumnDict = \
portal_catalog.getSecurityUidListAndRoleColumnDict
security_query_cache_dict = {}
@@ -490,8 +496,7 @@
getWorklistListQuery(grouped_worklist_dict=grouped_worklist_dict)
group_by_expression = ', '.join(total_criterion_id_list)
assert COUNT_COLUMN_TITLE not in total_criterion_id_list
- select_expression = 'count(*) as %s, %s' % (COUNT_COLUMN_TITLE,
- group_by_expression)
+ select_expression = select_expression_prefix + group_by_expression
search_result_kw = {'select_expression': select_expression,
'group_by_expression': group_by_expression,
'query': query}
@@ -520,3 +525,57 @@
return actions
WorkflowTool.listActions = WorkflowTool_listActions
+
+def WorkflowTool_refreshWorklistCache(self):
+ # XXX: Code below is duplicated from WorkflowTool_listActions
+ info = self._getOAI(None)
+ worklist_dict = {}
+ wf_ids = self.getWorkflowIds()
+ for wf_id in wf_ids:
+ wf = self.getWorkflowById(wf_id)
+ if wf is not None:
+ a = wf.getWorklistVariableMatchDict(info)
+ if a is not None:
+ worklist_dict[wf_id] = a
+ # End of duplicated code
+ if len(worklist_dict):
+ self.zCreateWorklistTable() # Create (or flush existing) table
+ portal_catalog = getToolByName(self, 'portal_catalog')
+ search_result = portal_catalog.unrestrictedSearchResults
+ acceptable_key_dict = portal_catalog.getSQLCatalog().getColumnMap()
+ table_column_id_set = ImmutableSet([COUNT_COLUMN_TITLE, 'security_uid', 'simulation_state', 'validation_state', 'portal_type', 'owner'])
+ security_column_id_list = ['security_uid']
+ (worklist_list_grouped_by_condition, worklist_metadata) = \
+ groupWorklistListByCondition(
+ worklist_dict=worklist_dict,
+ acceptable_key_dict=acceptable_key_dict)
+ for grouped_worklist_dict in worklist_list_grouped_by_condition:
+ # Generate the query for this worklist_list
+ (total_criterion_id_list, query) = \
+ getWorklistListQuery(grouped_worklist_dict=grouped_worklist_dict)
+ for criterion_id in total_criterion_id_list:
+ assert criterion_id in table_column_id_set
+ for security_column_id in security_column_id_list:
+ assert security_column_id not in total_criterion_id_list
+ assert security_column_id in table_column_id_set
+ total_criterion_id_list.append(security_column_id)
+ group_by_expression = ', '.join(total_criterion_id_list)
+ assert COUNT_COLUMN_TITLE not in total_criterion_id_list
+ assert COUNT_COLUMN_TITLE in table_column_id_set
+ select_expression = 'count(*) as %s, %s' % (COUNT_COLUMN_TITLE,
+ group_by_expression)
+ search_result_kw = {'select_expression': select_expression,
+ 'group_by_expression': group_by_expression,
+ 'query': query}
+ #LOG('WorklistGeneration', WARNING, 'Using query: %s' % \
+ # (search_result(src__=1, **search_result_kw), ))
+ catalog_brain_result = search_result(**search_result_kw)
+ value_column_dict = dict([(x, []) for x in table_column_id_set])
+ for catalog_brain_line in catalog_brain_result.dictionaries():
+ for column_id, value in catalog_brain_line.iteritems():
+ if column_id in value_column_dict:
+ value_column_dict[column_id].append(value)
+ if len(value_column_dict[COUNT_COLUMN_TITLE]):
+ self.zInsertIntoWorklistTable(**value_column_dict)
+
+WorkflowTool.refreshWorklistCache = WorkflowTool_refreshWorklistCache
More information about the Erp5-report
mailing list