Merge ~andrey-fedoseev/launchpad:fix-cvereport into launchpad:master

Proposed by Andrey Fedoseev
Status: Merged
Approved by: Andrey Fedoseev
Approved revision: 756e9b76a8abb122b8225eb3587982bcf68d19f2
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~andrey-fedoseev/launchpad:fix-cvereport
Merge into: launchpad:master
Diff against target: 104 lines (+30/-17)
1 file modified
lib/lp/bugs/browser/cvereport.py (+30/-17)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+431036@code.launchpad.net

Commit message

CVEReportView: use lazy loading for `open_cve_bugtasks` and `resolved_cve_bugtasks`

Description of the change

Previously, these attributes were computed on view initialization, with the exception of the case when the context is a Distribution with no series.

Now, the attributes are always available, regardless of the context, but are computed on demand, when they are actually used.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) wrote :

LGTM

P.S.: I think for NamedTuples the ship has sailed :-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/bugs/browser/cvereport.py b/lib/lp/bugs/browser/cvereport.py
2index 393cd91..e2f2f7d 100644
3--- a/lib/lp/bugs/browser/cvereport.py
4+++ b/lib/lp/bugs/browser/cvereport.py
5@@ -8,15 +8,17 @@ __all__ = [
6 "CVEReportView",
7 ]
8
9+from typing import List, NamedTuple
10+
11 from zope.component import getUtility
12
13 from lp.bugs.browser.buglisting import BugTaskListingItem
14 from lp.bugs.interfaces.bugtask import RESOLVED_BUGTASK_STATUSES, IBugTaskSet
15 from lp.bugs.interfaces.bugtasksearch import BugTaskSearchParams
16 from lp.bugs.interfaces.cve import ICveSet
17-from lp.registry.interfaces.distribution import IDistribution
18 from lp.registry.interfaces.person import IPersonSet
19 from lp.services.helpers import shortlist
20+from lp.services.propertycache import cachedproperty
21 from lp.services.webapp import LaunchpadView
22 from lp.services.webapp.escaping import structured
23 from lp.services.webapp.publisher import canonical_url
24@@ -37,6 +39,15 @@ class BugTaskCve:
25 return self.bugtasks[0].bug
26
27
28+BugTaskCves = NamedTuple(
29+ "BugTaskCves",
30+ (
31+ ("open", List[BugTaskCve]),
32+ ("resolved", List[BugTaskCve]),
33+ ),
34+)
35+
36+
37 def get_cve_display_data(cve):
38 """Return the data we need for display for the given CVE."""
39 return {
40@@ -63,18 +74,18 @@ class CVEReportView(LaunchpadView):
41 """Update the search params for the context for a specific view."""
42 raise NotImplementedError
43
44- def initialize(self):
45- """See `LaunchpadView`."""
46- super().initialize()
47- self.open_cve_bugtasks = []
48- self.resolved_cve_bugtasks = []
49+ @property
50+ def open_cve_bugtasks(self) -> List[BugTaskCve]:
51+ return self._bugtaskcves.open
52
53- # If we are dealing with a distribution with one or more series,
54- # there is no need to deal with the open and resolved CVE bugtasks.
55- # This is because the template only renders links to the CVE report
56- # page of each available series.
57- if IDistribution.providedBy(self.context) and self.context.series:
58- return
59+ @property
60+ def resolved_cve_bugtasks(self) -> List[BugTaskCve]:
61+ return self._bugtaskcves.resolved
62+
63+ @cachedproperty
64+ def _bugtaskcves(self) -> BugTaskCves:
65+
66+ bugtaskcves = BugTaskCves(open=[], resolved=[])
67
68 search_params = BugTaskSearchParams(self.user, has_cve=True)
69 bugtasks = shortlist(
70@@ -82,7 +93,7 @@ class CVEReportView(LaunchpadView):
71 )
72
73 if not bugtasks:
74- return
75+ return bugtaskcves
76
77 bugtask_set = getUtility(IBugTaskSet)
78 badge_properties = bugtask_set.getBugTaskBadgeProperties(bugtasks)
79@@ -121,13 +132,13 @@ class CVEReportView(LaunchpadView):
80
81 # Order the dictionary items by bug ID and then store only the
82 # bugtaskcve objects.
83- self.open_cve_bugtasks = [
84+ bugtaskcves.open.extend(
85 bugtaskcve for bug, bugtaskcve in sorted(open_bugtaskcves.items())
86- ]
87- self.resolved_cve_bugtasks = [
88+ )
89+ bugtaskcves.resolved.extend(
90 bugtaskcve
91 for bug, bugtaskcve in sorted(resolved_bugtaskcves.items())
92- ]
93+ )
94
95 # The page contains links to the bug task assignees:
96 # Pre-load the related Person and ValidPersonCache records
97@@ -138,6 +149,8 @@ class CVEReportView(LaunchpadView):
98 )
99 )
100
101+ return bugtaskcves
102+
103 def renderCVELinks(self, cves):
104 """Render the CVE links related to the given bug.
105

Subscribers

People subscribed via source and target branches

to status/vote changes: