← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/bug-731071 into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/bug-731071 into lp:launchpad.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  #731071 Archive:+copy-packages Package copy acknowledgement message causes many BinaryPackageName lookups
  https://bugs.launchpad.net/bugs/731071

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/bug-731071/+merge/52516

This removes the last per-binary queries from Archive:+copy-packages, by preloading BinaryPackageNames before rendering displaynames into a notification.
-- 
https://code.launchpad.net/~wgrant/launchpad/bug-731071/+merge/52516
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/bug-731071 into lp:launchpad.
=== modified file 'lib/lp/soyuz/browser/archive.py'
--- lib/lp/soyuz/browser/archive.py	2011-03-04 05:54:40 +0000
+++ lib/lp/soyuz/browser/archive.py	2011-03-08 06:14:57 +0000
@@ -36,7 +36,6 @@
 import pytz
 from sqlobject import SQLObjectNotFound
 from storm.expr import Desc
-from storm.zope.interfaces import IResultSet
 from zope.app.form.browser import TextAreaWidget
 from zope.component import getUtility
 from zope.formlib import form
@@ -62,6 +61,7 @@
 from canonical.launchpad.components.tokens import create_token
 from canonical.launchpad.helpers import english_list
 from canonical.launchpad.interfaces.launchpad import ILaunchpadCelebrities
+from canonical.launchpad.interfaces.lpstorm import IStore
 from canonical.launchpad.webapp import (
     canonical_url,
     enabled_with_permission,
@@ -151,7 +151,11 @@
     IPublishingSet,
     )
 from lp.soyuz.model.archive import Archive
-from lp.soyuz.model.publishing import SourcePackagePublishingHistory
+from lp.soyuz.model.binarypackagename import BinaryPackageName
+from lp.soyuz.model.publishing import (
+    BinaryPackagePublishingHistory,
+    SourcePackagePublishingHistory,
+    )
 from lp.soyuz.scripts.packagecopier import do_copy
 
 
@@ -1389,6 +1393,15 @@
                 'selected_sources', structured('\n'.join(messages)))
             return
 
+        # Preload BPNs to save queries when calculating display names.
+        needed_bpn_ids = set(
+            copy.binarypackagerelease.binarypackagenameID for copy in copies
+            if isinstance(copy, BinaryPackagePublishingHistory))
+        if needed_bpn_ids:
+            list(IStore(BinaryPackageName).find(
+                BinaryPackageName,
+                BinaryPackageName.id.is_in(needed_bpn_ids)))
+
         # Present a page notification describing the action.
         messages = []
         destination_url = canonical_url(destination_archive) + '/+packages'