launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #29274
[Merge] ~lgp171188/launchpad:fix-distribution-cvereport-page-timeout into launchpad:master
Guruprasad has proposed merging ~lgp171188/launchpad:fix-distribution-cvereport-page-timeout into launchpad:master.
Commit message:
Avoid unnecessary queries in the distribution cvereport page
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~lgp171188/launchpad/+git/launchpad/+merge/430886
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~lgp171188/launchpad:fix-distribution-cvereport-page-timeout into launchpad:master.
diff --git a/lib/lp/bugs/browser/cvereport.py b/lib/lp/bugs/browser/cvereport.py
index c2f1b65..fff4f2b 100644
--- a/lib/lp/bugs/browser/cvereport.py
+++ b/lib/lp/bugs/browser/cvereport.py
@@ -9,12 +9,14 @@ __all__ = [
]
from zope.component import getUtility
+from zope.security.proxy import removeSecurityProxy
from lp.bugs.browser.buglisting import BugTaskListingItem
from lp.bugs.interfaces.bugtask import RESOLVED_BUGTASK_STATUSES, IBugTaskSet
from lp.bugs.interfaces.bugtasksearch import BugTaskSearchParams
from lp.bugs.interfaces.cve import ICveSet
from lp.registry.interfaces.person import IPersonSet
+from lp.registry.model.distribution import Distribution
from lp.services.helpers import shortlist
from lp.services.webapp import LaunchpadView
from lp.services.webapp.escaping import structured
@@ -65,14 +67,25 @@ class CVEReportView(LaunchpadView):
def initialize(self):
"""See `LaunchpadView`."""
super().initialize()
+ self.open_cve_bugtasks = []
+ self.resolved_cve_bugtasks = []
+
+ # If we are dealing with a distribution with one or more series,
+ # there is no need to deal with the open and resolved CVE bugtasks.
+ # This is because the template only renders links to the CVE report
+ # page of each available series.
+ if (
+ isinstance(removeSecurityProxy(self.context), Distribution)
+ and self.context.series
+ ):
+ return
+
search_params = BugTaskSearchParams(self.user, has_cve=True)
bugtasks = shortlist(
self.context.searchTasks(search_params), longest_expected=600
)
if not bugtasks:
- self.open_cve_bugtasks = []
- self.resolved_cve_bugtasks = []
return
bugtask_set = getUtility(IBugTaskSet)
diff --git a/lib/lp/bugs/browser/tests/test_cvereport.py b/lib/lp/bugs/browser/tests/test_cvereport.py
index cf09cf1..6cd68e9 100644
--- a/lib/lp/bugs/browser/tests/test_cvereport.py
+++ b/lib/lp/bugs/browser/tests/test_cvereport.py
@@ -7,6 +7,8 @@ import re
from functools import partial
from operator import attrgetter
+from soupmatchers import HTMLContains, Tag
+
from lp.bugs.browser.cvereport import BugTaskCve
from lp.bugs.interfaces.bugtask import (
RESOLVED_BUGTASK_STATUSES,
@@ -78,6 +80,44 @@ class TestCVEReportView(TestCaseWithFactory):
yield cves[cve_index]
cve_index = (cve_index + 1) % NUM_CVES
+ def test_distribution_cvereport(self):
+ distribution = self.factory.makeDistribution()
+ distroseries1 = self.factory.makeDistroSeries(
+ distribution=distribution
+ )
+ distroseries2 = self.factory.makeDistroSeries(
+ distribution=distribution
+ )
+ view = create_initialized_view(distribution, "+cve")
+
+ self.assertFalse(view.open_cve_bugtasks)
+ self.assertFalse(view.resolved_cve_bugtasks)
+ self.assertThat(
+ view.render(),
+ HTMLContains(
+ Tag(
+ "distroseries 1 link",
+ "a",
+ attrs={
+ "href": "{}/+cve".format(
+ canonical_url(distroseries1, force_local_path=True)
+ )
+ },
+ text=distroseries1.displayname,
+ ),
+ Tag(
+ "distroseries 2 link",
+ "a",
+ attrs={
+ "href": "{}/+cve".format(
+ canonical_url(distroseries2, force_local_path=True)
+ )
+ },
+ text=distroseries2.displayname,
+ ),
+ ),
+ )
+
def test_render(self):
# The rendered page contains all expected CVE links.
html_data = self.view.render()
References