Merge lp:~stevenk/launchpad/preload-subscriptions-redux into lp:launchpad

Proposed by Steve Kowalik
Status: Merged
Approved by: William Grant
Approved revision: no longer in the source branch.
Merged at revision: 16523
Proposed branch: lp:~stevenk/launchpad/preload-subscriptions-redux
Merge into: lp:launchpad
Diff against target: 62 lines (+20/-3)
3 files modified
lib/lp/services/webapp/authorization.py (+11/-0)
lib/lp/soyuz/browser/archivesubscription.py (+4/-2)
lib/lp/soyuz/tests/test_archive_subscriptions.py (+5/-1)
To merge this branch: bzr merge lp:~stevenk/launchpad/preload-subscriptions-redux
Reviewer Review Type Date Requested Status
William Grant code Approve
Review via email: mp+152302@code.launchpad.net

Commit message

Precache permissions for the archivesubscriptions in Person:+archivesubscriptions.

Description of the change

It turns out my earlier fix for this work only helped for archivesubscriptions that are held personally, and not for those which are granted to teams. I have solved this by precaching the permissions for the subscriptions, and changing the test to create 5 team subscriptions.

lp.services.webapp.authorization has grown an __all__, since it did not have one.

To post a comment you must log in.
Revision history for this message
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lib/lp/services/webapp/authorization.py'
--- lib/lp/services/webapp/authorization.py 2012-08-09 03:50:49 +0000
+++ lib/lp/services/webapp/authorization.py 2013-03-07 22:55:36 +0000
@@ -3,6 +3,17 @@
33
4__metaclass__ = type4__metaclass__ = type
55
6__all__ = [
7 'available_with_permission',
8 'check_permission',
9 'clear_cache',
10 'iter_authorization',
11 'LaunchpadPermissiveSecurityPolicy',
12 'LaunchpadSecurityPolicy',
13 'LAUNCHPAD_SECURITY_POLICY_CACHE_KEY',
14 'precache_permission_for_objects',
15 ]
16
6from collections import (17from collections import (
7 deque,18 deque,
8 Iterable,19 Iterable,
920
=== modified file 'lib/lp/soyuz/browser/archivesubscription.py'
--- lib/lp/soyuz/browser/archivesubscription.py 2013-03-07 01:09:59 +0000
+++ lib/lp/soyuz/browser/archivesubscription.py 2013-03-07 22:55:36 +0000
@@ -49,6 +49,7 @@
49 cachedproperty,49 cachedproperty,
50 get_property_cache,50 get_property_cache,
51 )51 )
52from lp.services.webapp.authorization import precache_permission_for_objects
52from lp.services.webapp.batching import (53from lp.services.webapp.batching import (
53 BatchNavigator,54 BatchNavigator,
54 StormRangeFactory,55 StormRangeFactory,
@@ -329,8 +330,9 @@
329 subs_with_tokens = subscriber_set.getBySubscriberWithActiveToken(330 subs_with_tokens = subscriber_set.getBySubscriberWithActiveToken(
330 self.context)331 self.context)
331332
332 archives = load_related(333 subscriptions = map(itemgetter(0), subs_with_tokens)
333 Archive, map(itemgetter(0), subs_with_tokens), ['archive_id'])334 precache_permission_for_objects(None, 'launchpad.View', subscriptions)
335 archives = load_related(Archive, subscriptions, ['archive_id'])
334 list(getUtility(IPersonSet).getPrecachedPersonsFromIDs(336 list(getUtility(IPersonSet).getPrecachedPersonsFromIDs(
335 [archive.ownerID for archive in archives], need_validity=True))337 [archive.ownerID for archive in archives], need_validity=True))
336 for archive in archives:338 for archive in archives:
337339
=== modified file 'lib/lp/soyuz/tests/test_archive_subscriptions.py'
--- lib/lp/soyuz/tests/test_archive_subscriptions.py 2013-03-07 01:09:59 +0000
+++ lib/lp/soyuz/tests/test_archive_subscriptions.py 2013-03-07 22:55:36 +0000
@@ -181,7 +181,11 @@
181 for x in range(10):181 for x in range(10):
182 archive = self.factory.makeArchive(private=True)182 archive = self.factory.makeArchive(private=True)
183 with person_logged_in(archive.owner):183 with person_logged_in(archive.owner):
184 archive.newSubscription(subscriber, archive.owner)184 if x >= 5:
185 team = self.factory.makeTeam(members=[subscriber])
186 archive.newSubscription(team, archive.owner)
187 else:
188 archive.newSubscription(subscriber, archive.owner)
185 Store.of(subscriber).flush()189 Store.of(subscriber).flush()
186 Store.of(subscriber).invalidate()190 Store.of(subscriber).invalidate()
187 with person_logged_in(subscriber):191 with person_logged_in(subscriber):