Merge lp:~deryck/launchpad/adapt-badges-listing-item-901122 into lp:launchpad

Proposed by Deryck Hodge
Status: Merged
Approved by: Deryck Hodge
Approved revision: no longer in the source branch.
Merged at revision: 14889
Proposed branch: lp:~deryck/launchpad/adapt-badges-listing-item-901122
Merge into: lp:launchpad
Prerequisite: lp:~deryck/launchpad/preload-tags-for-buglistings-901122
Diff against target: 50 lines (+28/-1)
2 files modified
lib/lp/bugs/browser/bugtask.py (+1/-1)
lib/lp/bugs/browser/tests/test_bugtask.py (+27/-0)
To merge this branch: bzr merge lp:~deryck/launchpad/adapt-badges-listing-item-901122
Reviewer Review Type Date Requested Status
Steve Kowalik (community) code Approve
Review via email: mp+95063@code.launchpad.net

Commit message

Ensure bug listing code adapts badges for display via BugTaskListingItemImageDisplayAPI to save queries.

Description of the change

This is the second and final branch in getting the new bug data we added in custom buglistings loading with less queries. This is a simple one line fix with a lot of power. There's already a class to ensure we don't issue too many queries when getting badges. See lp.app.browser.tales.BugTaskListingItemImageDisplayAPI. But there is also it's super class lp.app.browser.tales.BugTaskImageDisplayAPI. Since we were adapting based on bugtasks rather than self (which is the BugTaskListingItem) we were adapting to the super class and not BugTaskListingItemImageDisplayAPI, which is the class that helps us avoid the additional queries.

This fix is magical. It brings us back down to pre-custom buglistings query levels +2. But the +2 is consistent no matter the data size, and are attributed to cached queries to get tags and reporter name.

lifeless suggested I add a scaling test in the pre-req branch for this one, which I'll gladly add into this branch before considering the work done.

To post a comment you must log in.
Revision history for this message
Steve Kowalik (stevenk) wrote :

Excellent work! I will echo Robert's suggestion of a query counting test, too.

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/bugs/browser/bugtask.py'
2--- lib/lp/bugs/browser/bugtask.py 2012-02-29 21:51:21 +0000
3+++ lib/lp/bugs/browser/bugtask.py 2012-02-29 21:51:22 +0000
4@@ -2200,7 +2200,7 @@
5 date_last_updated = self.bug.date_last_updated
6 last_updated_formatter = DateTimeFormatterAPI(date_last_updated)
7 last_updated = last_updated_formatter.displaydate()
8- badges = getAdapter(self.bugtask, IPathAdapter, 'image').badges()
9+ badges = getAdapter(self, IPathAdapter, 'image').badges()
10 target_image = getAdapter(self.target, IPathAdapter, 'image')
11 if self.bugtask.milestone is not None:
12 milestone_name = self.bugtask.milestone.displayname
13
14=== modified file 'lib/lp/bugs/browser/tests/test_bugtask.py'
15--- lib/lp/bugs/browser/tests/test_bugtask.py 2012-02-29 21:51:21 +0000
16+++ lib/lp/bugs/browser/tests/test_bugtask.py 2012-02-29 21:51:22 +0000
17@@ -1859,6 +1859,33 @@
18 view.initialize()
19 return view
20
21+ def invalidate_caches(self, obj):
22+ store = Store.of(obj)
23+ # Make sure everything is in the database.
24+ store.flush()
25+ # And invalidate the cache (not a reset, because that stops us using
26+ # the domain objects)
27+ store.invalidate()
28+
29+ def test_rendered_query_counts_constant_with_many_bugtasks(self):
30+ product = self.factory.makeProduct()
31+ bug = self.factory.makeBug(product=product)
32+ buggy_product = self.factory.makeProduct()
33+ for _ in range(10):
34+ self.factory.makeBug(product=buggy_product)
35+ recorder = QueryCollector()
36+ recorder.register()
37+ self.addCleanup(recorder.unregister)
38+ self.invalidate_caches(bug)
39+ # count with single task
40+ url = canonical_url(product, view_name='+bugs')
41+ self.getUserBrowser(url)
42+ self.assertThat(recorder, HasQueryCount(LessThan(24)))
43+ # count with many tasks
44+ buggy_url = canonical_url(buggy_product, view_name='+bugs')
45+ self.getUserBrowser(buggy_url)
46+ self.assertThat(recorder, HasQueryCount(LessThan(24)))
47+
48 def test_mustache_model_missing_if_no_flag(self):
49 """The IJSONRequestCache should contain mustache_model."""
50 view = self.makeView()