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
1=== modified file 'lib/lp/services/webapp/authorization.py'
2--- lib/lp/services/webapp/authorization.py 2012-08-09 03:50:49 +0000
3+++ lib/lp/services/webapp/authorization.py 2013-03-07 22:55:36 +0000
4@@ -3,6 +3,17 @@
5
6 __metaclass__ = type
7
8+__all__ = [
9+ 'available_with_permission',
10+ 'check_permission',
11+ 'clear_cache',
12+ 'iter_authorization',
13+ 'LaunchpadPermissiveSecurityPolicy',
14+ 'LaunchpadSecurityPolicy',
15+ 'LAUNCHPAD_SECURITY_POLICY_CACHE_KEY',
16+ 'precache_permission_for_objects',
17+ ]
18+
19 from collections import (
20 deque,
21 Iterable,
22
23=== modified file 'lib/lp/soyuz/browser/archivesubscription.py'
24--- lib/lp/soyuz/browser/archivesubscription.py 2013-03-07 01:09:59 +0000
25+++ lib/lp/soyuz/browser/archivesubscription.py 2013-03-07 22:55:36 +0000
26@@ -49,6 +49,7 @@
27 cachedproperty,
28 get_property_cache,
29 )
30+from lp.services.webapp.authorization import precache_permission_for_objects
31 from lp.services.webapp.batching import (
32 BatchNavigator,
33 StormRangeFactory,
34@@ -329,8 +330,9 @@
35 subs_with_tokens = subscriber_set.getBySubscriberWithActiveToken(
36 self.context)
37
38- archives = load_related(
39- Archive, map(itemgetter(0), subs_with_tokens), ['archive_id'])
40+ subscriptions = map(itemgetter(0), subs_with_tokens)
41+ precache_permission_for_objects(None, 'launchpad.View', subscriptions)
42+ archives = load_related(Archive, subscriptions, ['archive_id'])
43 list(getUtility(IPersonSet).getPrecachedPersonsFromIDs(
44 [archive.ownerID for archive in archives], need_validity=True))
45 for archive in archives:
46
47=== modified file 'lib/lp/soyuz/tests/test_archive_subscriptions.py'
48--- lib/lp/soyuz/tests/test_archive_subscriptions.py 2013-03-07 01:09:59 +0000
49+++ lib/lp/soyuz/tests/test_archive_subscriptions.py 2013-03-07 22:55:36 +0000
50@@ -181,7 +181,11 @@
51 for x in range(10):
52 archive = self.factory.makeArchive(private=True)
53 with person_logged_in(archive.owner):
54- archive.newSubscription(subscriber, archive.owner)
55+ if x >= 5:
56+ team = self.factory.makeTeam(members=[subscriber])
57+ archive.newSubscription(team, archive.owner)
58+ else:
59+ archive.newSubscription(subscriber, archive.owner)
60 Store.of(subscriber).flush()
61 Store.of(subscriber).invalidate()
62 with person_logged_in(subscriber):