Merge lp:~james-w/canonical-identity-provider/fast-team-memberships into lp:canonical-identity-provider/release

Proposed by James Westby
Status: Merged
Approved by: Natalia Bidart
Approved revision: no longer in the source branch.
Merged at revision: 1024
Proposed branch: lp:~james-w/canonical-identity-provider/fast-team-memberships
Merge into: lp:canonical-identity-provider/release
Diff against target: 30 lines (+5/-11)
1 file modified
src/identityprovider/models/team.py (+5/-11)
To merge this branch: bzr merge lp:~james-w/canonical-identity-provider/fast-team-memberships
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Ricardo Kirkner (community) Approve
Review via email: mp+181851@code.launchpad.net

Commit message

Rewrite the team participation query to run much faster.

This version ran the sample query in 3ms, vs. >11000ms for the old query.

Thanks to wgrant and nessita for figuring out how to make it fast.

Description of the change

Hi,

This should be a huge speedup to team participation queries, thanks to
wgrant and nessita.

Thanks,

James

To post a comment you must log in.
Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

LGTM

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/identityprovider/models/team.py'
2--- src/identityprovider/models/team.py 2013-08-23 13:03:58 +0000
3+++ src/identityprovider/models/team.py 2013-08-23 15:02:29 +0000
4@@ -17,21 +17,15 @@
5 # Someone that has no person associated with the account can't
6 # be a member of any teams.
7 return []
8- teams = Person.objects.filter(
9- name__in=team_names, # All team names provided
10- teamowner__isnull=False, # Only teams
11+ teams = TeamParticipation.objects.filter(
12+ person=user.person,
13+ team__name__in=team_names,
14 )
15 if not include_private:
16 teams = teams.filter(
17- visibility=PERSON_VISIBILITY_PUBLIC)
18- # Only teams in which the user is a member.
19- # Only actual membership counts: If the user owns a team but isn't a
20- # member, they aren't a member.
21- teams = teams.filter(
22- models.Q(team_participations__person=user.person)
23- )
24+ team__visibility=PERSON_VISIBILITY_PUBLIC)
25 # By default it's a query set result, not a true list
26- return list(teams.values_list('name', flat=True))
27+ return list(teams.values_list('team__name', flat=True))
28
29
30 class TeamParticipation(models.Model):