← Back to team overview

launchpad-reviewers team mailing list archive

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

 

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

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #741092 in Launchpad itself: "Archive:+subscriptions times out with many subscribers"
  https://bugs.launchpad.net/launchpad/+bug/741092

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

Eager load archivesubscribers.
-- 
https://code.launchpad.net/~lifeless/launchpad/bug-741092/+merge/55278
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/launchpad/bug-741092 into lp:launchpad.
=== modified file 'lib/lp/soyuz/browser/archivesubscription.py'
--- lib/lp/soyuz/browser/archivesubscription.py	2011-02-02 15:43:31 +0000
+++ lib/lp/soyuz/browser/archivesubscription.py	2011-03-29 04:59:27 +0000
@@ -15,6 +15,7 @@
     ]
 
 import datetime
+from operator import attrgetter
 
 import pytz
 from zope.app.form import CustomWidgetFactory
@@ -43,6 +44,7 @@
     )
 from lp.app.widgets.date import DateWidget
 from lp.app.widgets.popup import PersonPickerWidget
+from lp.registry.interfaces.person import IPersonSet
 from lp.services.fields import PersonChoice
 from lp.services.propertycache import cachedproperty
 from lp.soyuz.browser.sourceslist import (
@@ -153,15 +155,17 @@
     @property
     def subscriptions(self):
         """Return all the subscriptions for this archive."""
-        return getUtility(IArchiveSubscriberSet).getByArchive(
+        result = getUtility(IArchiveSubscriberSet).getByArchive(
             self.context)
+        ids = set(map(attrgetter('subscriber_id'), result))
+        list(getUtility(IPersonSet).getPrecachedPersonsFromIDs(ids,
+            need_validity=True))
+        return result
 
     @cachedproperty
     def has_subscriptions(self):
         """Return whether this archive has any subscribers."""
-        # XXX noodles 20090212 bug=246200: use bool() when it gets fixed
-        # in storm.
-        return self.subscriptions.any() is not None
+        return not self.subscriptions.is_empty()
 
     def validate_new_subscription(self, action, data):
         """Ensure the subscriber isn't already subscribed.

=== modified file 'lib/lp/soyuz/interfaces/archivesubscriber.py'
--- lib/lp/soyuz/interfaces/archivesubscriber.py	2010-08-23 17:26:42 +0000
+++ lib/lp/soyuz/interfaces/archivesubscriber.py	2011-03-29 04:59:27 +0000
@@ -19,7 +19,10 @@
     exported,
     )
 from lazr.restful.fields import Reference
-from zope.interface import Interface
+from zope.interface import (
+    Attribute,
+    Interface,
+    )
 from zope.schema import (
     Choice,
     Datetime,
@@ -61,7 +64,8 @@
         title=_("Subscriber"), required=True, readonly=True,
         vocabulary='ValidPersonOrTeam',
         description=_("The person who is subscribed.")))
-
+    subscriber_id = Attribute('database ID of the subscriber.')
+    
     date_expires = exported(Datetime(
         title=_("Date of Expiration"), required=False,
         description=_("The timestamp when the subscription will expire.")))