Commit 25ecabfe authored by Vincent Pelletier's avatar Vincent Pelletier

Use key-based sorting instead of cmp-based for performance.

Also reduces code duplication.
Also, use "sorted" rather than in-place sort and lambda rather than local
functions to reduce code length.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@45721 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent f87e1a76
...@@ -326,13 +326,8 @@ def getWorklistListQuery(grouped_worklist_dict): ...@@ -326,13 +326,8 @@ def getWorklistListQuery(grouped_worklist_dict):
criterion_value_to_worklist_dict = \ criterion_value_to_worklist_dict = \
criterion_value_to_worklist_dict_dict.setdefault(criterion_value, {}) criterion_value_to_worklist_dict_dict.setdefault(criterion_value, {})
criterion_value_to_worklist_dict[worklist_id] = None criterion_value_to_worklist_dict[worklist_id] = None
total_criterion_id_list = total_criterion_id_dict.keys() total_criterion_id_list = sorted(total_criterion_id_dict, key=lambda y: max(
def criterion_id_cmp(criterion_id_a, criterion_id_b): len(x) for x in total_criterion_id_dict[y].itervalues()))
return cmp(max([len(x) for x in \
total_criterion_id_dict[criterion_id_a].itervalues()]),
max([len(x) for x in \
total_criterion_id_dict[criterion_id_b].itervalues()]))
total_criterion_id_list.sort(criterion_id_cmp)
query = generateNestedQuery(priority_list=total_criterion_id_list, query = generateNestedQuery(priority_list=total_criterion_id_list,
criterion_dict=total_criterion_id_dict) criterion_dict=total_criterion_id_dict)
assert query is not None assert query is not None
...@@ -518,14 +513,13 @@ def WorkflowTool_listActions(self, info=None, object=None, src__=False): ...@@ -518,14 +513,13 @@ def WorkflowTool_listActions(self, info=None, object=None, src__=False):
for key, value in grouped_worklist_result.iteritems(): for key, value in grouped_worklist_result.iteritems():
worklist_result_dict[key] = value + worklist_result_dict.get(key, 0) worklist_result_dict[key] = value + worklist_result_dict.get(key, 0)
if not src__: if not src__:
action_list = generateActionList(worklist_metadata=worklist_metadata, action_list = sorted(
worklist_result=worklist_result_dict, generateActionList(
portal_url=portal_url) worklist_metadata=worklist_metadata,
def get_action_ident(action): worklist_result=worklist_result_dict,
return '/'.join((action['workflow_id'], action['worklist_id'])) portal_url=portal_url),
def action_cmp(action_a, action_b): key=lambda x: '/'.join((x['workflow_id'], x['worklist_id'])),
return cmp(get_action_ident(action_a), get_action_ident(action_b)) )
action_list.sort(action_cmp)
return action_list return action_list
user = str(_getAuthenticatedUser(self)) user = str(_getAuthenticatedUser(self))
if src__: if src__:
......
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