← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/buglinktarget-bulk into lp:launchpad.

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

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1802728 in Launchpad itself: "Some CVE pages time out constantly"
  https://bugs.launchpad.net/launchpad/+bug/1802728

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/buglinktarget-bulk/+merge/358644
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/buglinktarget-bulk into lp:launchpad.
=== modified file 'lib/lp/bugs/browser/buglinktarget.py'
--- lib/lp/bugs/browser/buglinktarget.py	2018-07-16 00:46:56 +0000
+++ lib/lp/bugs/browser/buglinktarget.py	2018-11-12 16:06:23 +0000
@@ -106,6 +106,8 @@
         for task in bugtasks:
             bugs[task.bug].append(task)
         badges = bugtask_set.getBugTaskBadgeProperties(bugtasks)
+        tags = bugtask_set.getBugTaskTags(bugtasks)
+        people = bugtask_set.getBugTaskPeople(bugtasks)
         links = []
         columns_to_show = ["id", "summary", "bugtargetdisplayname",
             "importance", "status"]
@@ -114,6 +116,8 @@
                 columns_to_show=columns_to_show,
                 size=config.malone.buglist_batch_size)
             get_property_cache(navigator).bug_badge_properties = badges
+            get_property_cache(navigator).tags_for_batch = tags
+            get_property_cache(navigator).bugtask_people = people
             links.append({
                 'bug': bug,
                 'title': bug.title,

=== modified file 'lib/lp/bugs/browser/tests/test_bugtask.py'
--- lib/lp/bugs/browser/tests/test_bugtask.py	2018-01-02 16:10:26 +0000
+++ lib/lp/bugs/browser/tests/test_bugtask.py	2018-11-12 16:06:23 +0000
@@ -175,7 +175,7 @@
         recorder1, recorder2 = record_two_runs(
             lambda: self.getUserBrowser(url, owner),
             make_merge_proposals, 0, 1)
-        self.assertThat(recorder1, HasQueryCount(LessThan(90)))
+        self.assertThat(recorder1, HasQueryCount(LessThan(92)))
         # Ideally this should be much fewer, but this tries to keep a win of
         # removing more than half of these.
         self.assertThat(

=== modified file 'lib/lp/bugs/browser/tests/test_cve.py'
--- lib/lp/bugs/browser/tests/test_cve.py	2012-02-28 04:24:19 +0000
+++ lib/lp/bugs/browser/tests/test_cve.py	2018-11-12 16:06:23 +0000
@@ -1,4 +1,4 @@
-# Copyright 2012 Canonical Ltd.  This software is licensed under the
+# Copyright 2012-2018 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """CVE related tests."""
@@ -13,10 +13,13 @@
     )
 from lp.services.webapp.publisher import canonical_url
 from lp.testing import (
+    login_person,
     person_logged_in,
+    record_two_runs,
     TestCaseWithFactory,
     )
 from lp.testing.layers import DatabaseFunctionalLayer
+from lp.testing.matchers import HasQueryCount
 from lp.testing.views import create_initialized_view
 
 
@@ -174,3 +177,22 @@
             '<span style="text-decoration: underline">CVE-2011-0456</span>'
             '</a>')
         self.assertEqual(expected, result)
+
+    def test_query_count(self):
+        cve = self.getCVE()
+        cve_url = canonical_url(cve)
+        person = self.factory.makePerson()
+
+        def make_bug_and_tasks():
+            bug = self.factory.makeBug()
+            self.factory.makeBugTask(
+                bug=bug, target=self.factory.makeProductSeries())
+            self.factory.makeBugTask(
+                bug=bug, target=self.factory.makeSourcePackage())
+            bug.linkCVE(cve, person)
+
+        recorder1, recorder2 = record_two_runs(
+            lambda: self.getUserBrowser(cve_url, person),
+            make_bug_and_tasks, 2, 10,
+            login_method=lambda: login_person(person))
+        self.assertThat(recorder2, HasQueryCount.byEquality(recorder1))

=== modified file 'lib/lp/bugs/model/bugtask.py'
--- lib/lp/bugs/model/bugtask.py	2016-05-05 08:23:13 +0000
+++ lib/lp/bugs/model/bugtask.py	2018-11-12 16:06:23 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2016 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2018 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Classes that implement IBugTask and its related interfaces."""
@@ -1480,7 +1480,10 @@
             claim they were inefficient and unwanted.
         """
         # Prevent circular import problems.
+        from lp.registry.model.distribution import Distribution
+        from lp.registry.model.distroseries import DistroSeries
         from lp.registry.model.product import Product
+        from lp.registry.model.productseries import ProductSeries
         from lp.bugs.model.bug import Bug
         from lp.bugs.model.bugtasksearch import search_bugs
         _noprejoins = kwargs.get('_noprejoins', False)
@@ -1490,6 +1493,9 @@
             def eager_load(rows):
                 load_related(Bug, rows, ['bugID'])
                 load_related(Product, rows, ['productID'])
+                load_related(ProductSeries, rows, ['productseriesID'])
+                load_related(Distribution, rows, ['distributionID'])
+                load_related(DistroSeries, rows, ['distroseriesID'])
                 load_related(SourcePackageName, rows, ['sourcepackagenameID'])
         return search_bugs(eager_load, (params,) + args)
 

=== modified file 'lib/lp/bugs/tests/test_bugsearch_conjoined.py'
--- lib/lp/bugs/tests/test_bugsearch_conjoined.py	2015-01-29 14:14:01 +0000
+++ lib/lp/bugs/tests/test_bugsearch_conjoined.py	2018-11-12 16:06:23 +0000
@@ -277,7 +277,7 @@
         Store.of(self.milestone).flush()
         with StormStatementRecorder() as recorder:
             list(self.bugtask_set.search(self.params))
-        self.assertThat(recorder, HasQueryCount(Equals(4)))
+        self.assertThat(recorder, HasQueryCount(Equals(5)))
 
     def test_search_results_count_with_other_productseries_tasks(self):
         # Test with zero conjoined masters and bugtasks targeted to


Follow ups