← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/bug-1352539 into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/bug-1352539 into lp:launchpad.

Commit message:
Fix Person.sub_teams and super_teams to preload data for API fields.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1352539 in Launchpad itself: "some user team enumeration causes 503 response"
  https://bugs.launchpad.net/launchpad/+bug/1352539

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/bug-1352539/+merge/239277

Fix Person.sub_teams and super_teams to preload data for API fields.
-- 
https://code.launchpad.net/~wgrant/launchpad/bug-1352539/+merge/239277
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/bug-1352539 into lp:launchpad.
=== modified file 'lib/lp/registry/model/person.py'
--- lib/lp/registry/model/person.py	2014-10-22 17:32:38 +0000
+++ lib/lp/registry/model/person.py	2014-10-22 19:30:11 +0000
@@ -1568,26 +1568,27 @@
     @property
     def super_teams(self):
         """See `IPerson`."""
-        return Store.of(self).using(
-            Join(
+        return PersonSet()._getPrecachedPersons(
+            [Join(
                 Person,
                 TeamParticipation,
-                Person.id == TeamParticipation.teamID
-            )).find(
-                Person,
-                TeamParticipation.personID == self.id,
-                TeamParticipation.teamID != self.id)
+                Person.id == TeamParticipation.teamID)],
+            And(TeamParticipation.personID == self.id,
+                TeamParticipation.teamID != self.id),
+            need_api=True)
 
     @property
     def sub_teams(self):
         """See `IPerson`."""
-        query = """
-            Person.id = TeamParticipation.person AND
-            TeamParticipation.team = %s AND
-            TeamParticipation.person != %s AND
-            Person.teamowner IS NOT NULL
-            """ % sqlvalues(self.id, self.id)
-        return Person.select(query, clauseTables=['TeamParticipation'])
+        return PersonSet()._getPrecachedPersons(
+            [Join(
+                Person,
+                TeamParticipation,
+                Person.id == TeamParticipation.personID)],
+            And(TeamParticipation.teamID == self.id,
+                TeamParticipation.personID != self.id,
+                Person.teamownerID != None),
+            need_api=True)
 
     def getTeamAdminsEmailAddresses(self):
         """See `IPerson`."""


Follow ups