Commit ae4be841 authored by Vincent Pelletier's avatar Vincent Pelletier

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.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17371 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent b5d34ab6
......@@ -27,6 +27,7 @@ from Products.CMFCore.utils import getToolByName
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 @@ def WorkflowTool_listActions(self, info=None, object=None):
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 @@ def WorkflowTool_listActions(self, info=None, object=None):
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 @@ def WorkflowTool_listActions(self, info=None, object=None):
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
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