Merge lp:~bac/launchpad/person-in-team into lp:launchpad

Proposed by Brad Crittenden
Status: Merged
Approved by: Brad Crittenden
Approved revision: no longer in the source branch.
Merged at revision: 12732
Proposed branch: lp:~bac/launchpad/person-in-team
Merge into: lp:launchpad
Diff against target: 37 lines (+5/-11)
1 file modified
lib/lp/bugs/browser/structuralsubscription.py (+5/-11)
To merge this branch: bzr merge lp:~bac/launchpad/person-in-team
Reviewer Review Type Date Requested Status
Benji York (community) code Approve
Review via email: mp+55928@code.launchpad.net

Commit message

[r=benji][no-qa] Replace person_is_team_admin with a better implementation.

Description of the change

= Summary =

The implementation of person_is_team_admin *appears* to be inefficient
and this fix *seems* to be better. Lots of hand waving here.

== Proposed fix ==

Get all of a users administered teams in one query and just check each
one subsequently.

== Pre-implementation notes ==

None

== Implementation details ==

As above.

== Tests ==

No test changes as test_expose seems to have good coverage and it is
just a reimplementation of existing functionality.

== Demo and Q/A ==

None

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/bugs/browser/structuralsubscription.py

To post a comment you must log in.
Revision history for this message
Benji York (benji) wrote :

Looks good.

Agreed regarding tests, this is a pure refactoring so if the existing test coverage is good, we should be fine there.

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/bugs/browser/structuralsubscription.py'
2--- lib/lp/bugs/browser/structuralsubscription.py 2011-03-30 20:19:44 +0000
3+++ lib/lp/bugs/browser/structuralsubscription.py 2011-04-01 20:28:35 +0000
4@@ -417,20 +417,14 @@
5 IJSONRequestCache(request).objects['administratedTeams'] = info
6
7
8-def person_is_team_admin(person, team):
9- answer = False
10- admins = team.adminmembers
11- for admin in admins:
12- if person.inTeam(admin):
13- answer = True
14- break
15- return answer
16-
17-
18 def expose_user_subscriptions_to_js(user, subscriptions, request):
19 """Make the user's subscriptions available to JavaScript."""
20 info = {}
21 api_request = IWebServiceClientRequest(request)
22+ if user is None:
23+ administered_teams = []
24+ else:
25+ administered_teams = user.getAdministratedTeams()
26 for subscription in subscriptions:
27 target = subscription.target
28 record = info.get(target)
29@@ -444,7 +438,7 @@
30 for filter in subscription.bug_filters:
31 is_team = subscriber.isTeam()
32 user_is_team_admin = (is_team and
33- person_is_team_admin(user, subscriber))
34+ subscriber in administered_teams)
35 record['filters'].append(dict(
36 filter=filter,
37 subscriber_link=absoluteURL(subscriber, api_request),