Merge lp:~cjwatson/launchpad/buglinktarget-bulk into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18823
Proposed branch: lp:~cjwatson/launchpad/buglinktarget-bulk
Merge into: lp:launchpad
Diff against target: 125 lines (+36/-4)
5 files modified
lib/lp/bugs/browser/buglinktarget.py (+4/-0)
lib/lp/bugs/browser/tests/test_bugtask.py (+1/-1)
lib/lp/bugs/browser/tests/test_cve.py (+23/-1)
lib/lp/bugs/model/bugtask.py (+7/-1)
lib/lp/bugs/tests/test_bugsearch_conjoined.py (+1/-1)
To merge this branch: bzr merge lp:~cjwatson/launchpad/buglinktarget-bulk
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+358644@code.launchpad.net

Commit message

Do more preloading in bug link target listing views such as Cve:+index.

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/bugs/browser/buglinktarget.py'
2--- lib/lp/bugs/browser/buglinktarget.py 2018-07-16 00:46:56 +0000
3+++ lib/lp/bugs/browser/buglinktarget.py 2018-11-12 16:06:23 +0000
4@@ -106,6 +106,8 @@
5 for task in bugtasks:
6 bugs[task.bug].append(task)
7 badges = bugtask_set.getBugTaskBadgeProperties(bugtasks)
8+ tags = bugtask_set.getBugTaskTags(bugtasks)
9+ people = bugtask_set.getBugTaskPeople(bugtasks)
10 links = []
11 columns_to_show = ["id", "summary", "bugtargetdisplayname",
12 "importance", "status"]
13@@ -114,6 +116,8 @@
14 columns_to_show=columns_to_show,
15 size=config.malone.buglist_batch_size)
16 get_property_cache(navigator).bug_badge_properties = badges
17+ get_property_cache(navigator).tags_for_batch = tags
18+ get_property_cache(navigator).bugtask_people = people
19 links.append({
20 'bug': bug,
21 'title': bug.title,
22
23=== modified file 'lib/lp/bugs/browser/tests/test_bugtask.py'
24--- lib/lp/bugs/browser/tests/test_bugtask.py 2018-01-02 16:10:26 +0000
25+++ lib/lp/bugs/browser/tests/test_bugtask.py 2018-11-12 16:06:23 +0000
26@@ -175,7 +175,7 @@
27 recorder1, recorder2 = record_two_runs(
28 lambda: self.getUserBrowser(url, owner),
29 make_merge_proposals, 0, 1)
30- self.assertThat(recorder1, HasQueryCount(LessThan(90)))
31+ self.assertThat(recorder1, HasQueryCount(LessThan(92)))
32 # Ideally this should be much fewer, but this tries to keep a win of
33 # removing more than half of these.
34 self.assertThat(
35
36=== modified file 'lib/lp/bugs/browser/tests/test_cve.py'
37--- lib/lp/bugs/browser/tests/test_cve.py 2012-02-28 04:24:19 +0000
38+++ lib/lp/bugs/browser/tests/test_cve.py 2018-11-12 16:06:23 +0000
39@@ -1,4 +1,4 @@
40-# Copyright 2012 Canonical Ltd. This software is licensed under the
41+# Copyright 2012-2018 Canonical Ltd. This software is licensed under the
42 # GNU Affero General Public License version 3 (see the file LICENSE).
43
44 """CVE related tests."""
45@@ -13,10 +13,13 @@
46 )
47 from lp.services.webapp.publisher import canonical_url
48 from lp.testing import (
49+ login_person,
50 person_logged_in,
51+ record_two_runs,
52 TestCaseWithFactory,
53 )
54 from lp.testing.layers import DatabaseFunctionalLayer
55+from lp.testing.matchers import HasQueryCount
56 from lp.testing.views import create_initialized_view
57
58
59@@ -174,3 +177,22 @@
60 '<span style="text-decoration: underline">CVE-2011-0456</span>'
61 '</a>')
62 self.assertEqual(expected, result)
63+
64+ def test_query_count(self):
65+ cve = self.getCVE()
66+ cve_url = canonical_url(cve)
67+ person = self.factory.makePerson()
68+
69+ def make_bug_and_tasks():
70+ bug = self.factory.makeBug()
71+ self.factory.makeBugTask(
72+ bug=bug, target=self.factory.makeProductSeries())
73+ self.factory.makeBugTask(
74+ bug=bug, target=self.factory.makeSourcePackage())
75+ bug.linkCVE(cve, person)
76+
77+ recorder1, recorder2 = record_two_runs(
78+ lambda: self.getUserBrowser(cve_url, person),
79+ make_bug_and_tasks, 2, 10,
80+ login_method=lambda: login_person(person))
81+ self.assertThat(recorder2, HasQueryCount.byEquality(recorder1))
82
83=== modified file 'lib/lp/bugs/model/bugtask.py'
84--- lib/lp/bugs/model/bugtask.py 2016-05-05 08:23:13 +0000
85+++ lib/lp/bugs/model/bugtask.py 2018-11-12 16:06:23 +0000
86@@ -1,4 +1,4 @@
87-# Copyright 2009-2016 Canonical Ltd. This software is licensed under the
88+# Copyright 2009-2018 Canonical Ltd. This software is licensed under the
89 # GNU Affero General Public License version 3 (see the file LICENSE).
90
91 """Classes that implement IBugTask and its related interfaces."""
92@@ -1480,7 +1480,10 @@
93 claim they were inefficient and unwanted.
94 """
95 # Prevent circular import problems.
96+ from lp.registry.model.distribution import Distribution
97+ from lp.registry.model.distroseries import DistroSeries
98 from lp.registry.model.product import Product
99+ from lp.registry.model.productseries import ProductSeries
100 from lp.bugs.model.bug import Bug
101 from lp.bugs.model.bugtasksearch import search_bugs
102 _noprejoins = kwargs.get('_noprejoins', False)
103@@ -1490,6 +1493,9 @@
104 def eager_load(rows):
105 load_related(Bug, rows, ['bugID'])
106 load_related(Product, rows, ['productID'])
107+ load_related(ProductSeries, rows, ['productseriesID'])
108+ load_related(Distribution, rows, ['distributionID'])
109+ load_related(DistroSeries, rows, ['distroseriesID'])
110 load_related(SourcePackageName, rows, ['sourcepackagenameID'])
111 return search_bugs(eager_load, (params,) + args)
112
113
114=== modified file 'lib/lp/bugs/tests/test_bugsearch_conjoined.py'
115--- lib/lp/bugs/tests/test_bugsearch_conjoined.py 2015-01-29 14:14:01 +0000
116+++ lib/lp/bugs/tests/test_bugsearch_conjoined.py 2018-11-12 16:06:23 +0000
117@@ -277,7 +277,7 @@
118 Store.of(self.milestone).flush()
119 with StormStatementRecorder() as recorder:
120 list(self.bugtask_set.search(self.params))
121- self.assertThat(recorder, HasQueryCount(Equals(4)))
122+ self.assertThat(recorder, HasQueryCount(Equals(5)))
123
124 def test_search_results_count_with_other_productseries_tasks(self):
125 # Test with zero conjoined masters and bugtasks targeted to