Merge lp:~stevenk/launchpad/better-person-preloading-specsearch into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: Steve Kowalik
Approved revision: no longer in the source branch.
Merged at revision: 16455
Proposed branch: lp:~stevenk/launchpad/better-person-preloading-specsearch
Merge into: lp:launchpad
Diff against target: 42 lines (+11/-6)
1 file modified
lib/lp/blueprints/model/specificationsearch.py (+11/-6)
To merge this branch: bzr merge lp:~stevenk/launchpad/better-person-preloading-specsearch
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+145316@code.launchpad.net

Commit message

Make use of pre_iter_hook to preload people in specificationsearch, rather than a decorator.

Description of the change

Make use of pre_iter_hook to preload people, rather than a decorator.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/blueprints/model/specificationsearch.py'
2--- lib/lp/blueprints/model/specificationsearch.py 2013-01-29 03:39:16 +0000
3+++ lib/lp/blueprints/model/specificationsearch.py 2013-01-29 07:10:30 +0000
4@@ -105,15 +105,17 @@
5 # Set the _known_viewers property for each specification, as well as
6 # preloading the people involved, if asked.
7 decorators = []
8+ preload_hook = None
9 if user is not None and not IPersonRoles(user).in_admin:
10 decorators.append(_make_cache_user_can_view_spec(user))
11 if prejoin_people:
12- decorators.append(_preload_specification_related_people)
13+ preload_hook = _preload_specifications_related_people
14 results = store.using(*tables).find(
15 Specification, *clauses).order_by(*order).config(limit=quantity)
16 return DecoratedResultSet(
17 results,
18- lambda row: reduce(lambda task, dec: dec(task), decorators, row))
19+ lambda row: reduce(lambda task, dec: dec(task), decorators, row),
20+ pre_iter_hook=preload_hook)
21
22
23 def get_specification_active_product_filter(context):
24@@ -223,11 +225,14 @@
25 return cache_user_can_view_spec
26
27
28-def _preload_specification_related_people(spec):
29+def _preload_specifications_related_people(rows):
30+ person_ids = set()
31+ for spec in rows:
32+ person_ids |= set(
33+ [spec._assigneeID, spec._approverID, spec._drafterID])
34+ person_ids -= set([None])
35 list(getUtility(IPersonSet).getPrecachedPersonsFromIDs(
36- [spec._assigneeID, spec._approverID, spec._drafterID],
37- need_validity=True))
38- return spec
39+ person_ids, need_validity=True))
40
41
42 def get_specification_started_clause():