← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~lifeless/launchpad/bug-727023 into lp:launchpad

 

Robert Collins has proposed merging lp:~lifeless/launchpad/bug-727023 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #727023 in Launchpad itself: "Cve:+index timeouts"
  https://bugs.launchpad.net/launchpad/+bug/727023

For more details, see:
https://code.launchpad.net/~lifeless/launchpad/bug-727023/+merge/55266

Change from using the edit row display for cve linked bug to the regular search display table. Also eager load bugs rather than trying-and-failing on each link.
-- 
https://code.launchpad.net/~lifeless/launchpad/bug-727023/+merge/55266
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/launchpad/bug-727023 into lp:launchpad.
=== modified file 'lib/lp/bugs/browser/buglinktarget.py'
--- lib/lp/bugs/browser/buglinktarget.py	2011-02-02 15:43:31 +0000
+++ lib/lp/bugs/browser/buglinktarget.py	2011-03-29 02:49:36 +0000
@@ -11,25 +11,38 @@
     'BugsUnlinkView',
     ]
 
+from collections import defaultdict
+from operator import attrgetter
+
 from lazr.lifecycle.event import ObjectModifiedEvent
 from lazr.lifecycle.snapshot import Snapshot
+from zope.component import getUtility
 from zope.event import notify
 from zope.interface import providedBy
 from zope.security.interfaces import Unauthorized
 
+from canonical.config import config
 from canonical.launchpad import _
+from canonical.launchpad.searchbuilder import any
 from canonical.launchpad.webapp import canonical_url
 from canonical.launchpad.webapp.authorization import check_permission
+from canonical.launchpad.webapp.publisher import LaunchpadView
 from lp.app.browser.launchpadform import (
     action,
     custom_widget,
     LaunchpadFormView,
     )
 from lp.app.widgets.itemswidgets import LabeledMultiCheckBoxWidget
+from lp.bugs.browser.bugtask import BugListingBatchNavigator
 from lp.bugs.interfaces.buglink import (
     IBugLinkForm,
     IUnlinkBugsForm,
     )
+from lp.bugs.interfaces.bugtask import BugTaskSearchParams, IBugTaskSet
+from lp.services.propertycache import (
+    cachedproperty,
+    get_property_cache,
+    )
 
 
 class BugLinkView(LaunchpadFormView):
@@ -72,26 +85,40 @@
         self.next_url = canonical_url(self.context)
 
 
-class BugLinksListingView:
+class BugLinksListingView(LaunchpadView):
     """View for displaying buglinks."""
 
-    def __init__(self, context, request):
-        self.context = context
-        self.request = request
-
+    @cachedproperty
     def buglinks(self):
         """Return a list of dict with bug, title and can_see_bug keys
         for the linked bugs. It makes the Right Thing(tm) with private bug.
         """
+        # Do a regular search to get the bugtasks so that visibility is
+        # evaluated and eager loading is performed.
+        bug_ids = map(attrgetter('bugID'), self.context.bug_links)
+        bugtask_set = getUtility(IBugTaskSet)
+        query = BugTaskSearchParams(user=self.user, bug=any(*bug_ids))
+        bugtasks = list(bugtask_set.search(query))
+        # collate by bug
+        bugs = defaultdict(list)
+        for task in bugtasks:
+            bugs[task.bug].append(task)
+        badges = bugtask_set.getBugTaskBadgeProperties(bugtasks)
         links = []
-        for bug in self.context.bugs:
-            try:
-                links.append(
-                    {'bug': bug, 'title': bug.title, 'can_view_bug': True})
-            except Unauthorized:
-                links.append(
-                    {'bug': bug, 'title': _('private bug'),
-                     'can_view_bug': False})
+        columns_to_show = ["id", "summary", "bugtargetdisplayname",
+            "importance", "status"]
+        for bug, tasks in bugs.items():
+            navigator = BugListingBatchNavigator(tasks, self.request,
+                columns_to_show=columns_to_show,
+                size=config.malone.buglist_batch_size)
+            get_property_cache(navigator).bug_badge_properties = badges
+            links.append({
+                'bug': bug,
+                'title': bug.title,
+                'can_view_bug': True,
+                'tasks': tasks,
+                'batch_navigator': navigator,
+                })
         return links
 
 

=== modified file 'lib/lp/bugs/interfaces/buglink.py'
--- lib/lp/bugs/interfaces/buglink.py	2011-03-24 13:16:48 +0000
+++ lib/lp/bugs/interfaces/buglink.py	2011-03-29 02:49:36 +0000
@@ -23,6 +23,7 @@
     Reference,
     )
 from zope.interface import (
+    Attribute,
     implements,
     Interface,
     )
@@ -50,6 +51,7 @@
 
     bug = BugField(title=_("The bug that is linked to."),
                    required=True, readonly=True)
+    bugID = Attribute("Database id of the bug.")
 
     target = Object(title=_("The object to which the bug is linked."),
                     required=True, readonly=True, schema=Interface)

=== modified file 'lib/lp/bugs/interfaces/bugtask.py'
--- lib/lp/bugs/interfaces/bugtask.py	2011-03-29 00:11:57 +0000
+++ lib/lp/bugs/interfaces/bugtask.py	2011-03-29 02:49:36 +0000
@@ -1159,7 +1159,7 @@
                  hardware_is_linked_to_bug=False,
                  linked_branches=None, linked_blueprints=None,
                  structural_subscriber=None, modified_since=None,
-                 created_since=None, exclude_conjoined_tasks=False):
+                 created_since=None, exclude_conjoined_tasks=False, cve=None):
 
         self.bug = bug
         self.searchtext = searchtext
@@ -1207,6 +1207,7 @@
         self.modified_since = modified_since
         self.created_since = created_since
         self.exclude_conjoined_tasks = exclude_conjoined_tasks
+        self.cve = cve
 
     def setProduct(self, product):
         """Set the upstream context on which to filter the search."""

=== modified file 'lib/lp/bugs/templates/cve-index.pt'
--- lib/lp/bugs/templates/cve-index.pt	2010-12-19 17:52:17 +0000
+++ lib/lp/bugs/templates/cve-index.pt	2011-03-29 02:49:36 +0000
@@ -22,7 +22,7 @@
       $CVE.description
     </tal:desc>
 
-  <div id="related-bugs" tal:condition="context/bugs">
+  <div id="related-bugs" tal:condition="view/buglinks">
     <h2>Related bugs and status</h2>
 
     <p>
@@ -32,18 +32,9 @@
 
     <div tal:repeat="link view/buglinks">
       <strong>
-        <a tal:condition="link/bug/required:launchpad.View"
-          tal:replace="structure link/bug/fmt:link"/>
-        <span class="sprite bug"
-          tal:condition="not: link/bug/required:launchpad.View">
-          Bug #<tal:number replace="link/bug/id" />:
-          <tal:title replace="link/title" />
-        </span>
+        <a tal:replace="structure link/bug/fmt:link"/>
       </strong>
-      <tal:details condition="link/can_view_bug">
-        <div
-          tal:replace="structure link/bug/@@+bugtasks-and-nominations-table" />
-      </tal:details>
+      <div tal:replace="structure link/batch_navigator/@@+table-view-without-navlinks" />
     </div>
   </div>