diff options
author | 2018-07-02 15:57:12 +0000 | |
---|---|---|
committer | 2018-07-02 15:57:12 +0000 | |
commit | 00b1e3a44eb2893a3c9d09a30243162ef3652d13 (patch) | |
tree | 606a344f799d6dbe87e3bec59598e0b29fe0b0c5 /pysite | |
parent | Merge branch 'momo/enhance-jam-index' into 'master' (diff) |
Optimize the team list, again.
Diffstat (limited to 'pysite')
-rw-r--r-- | pysite/views/main/jams/jam_team_list.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/pysite/views/main/jams/jam_team_list.py b/pysite/views/main/jams/jam_team_list.py index 49587e36..452a073f 100644 --- a/pysite/views/main/jams/jam_team_list.py +++ b/pysite/views/main/jams/jam_team_list.py @@ -20,17 +20,20 @@ class JamsTeamListView(RouteView, DBMixin, OAuthMixin): if not jam_obj: raise NotFound() - query = self.db.query(self.table_name).get_all(self.table_name, *jam_obj["teams"]).pluck( - ["id", "name", "members", "repo"]).merge( - lambda team: { - "members": - self.db.query("users") - .filter(lambda user: team["members"].contains(user["user_id"])) - .coerce_to("array") - }).coerce_to("array") + # Get all the participants of this jam + # Note: the group function will return a dict with user_ids as keys, however each element will be an array + participants_query = self.db.query("users").get_all(*jam_obj["participants"], index="user_id").group("user_id") + participants = self.db.run(participants_query) + # Get all the teams, leaving the team members as only an array of IDs + query = self.db.query(self.table_name).get_all(self.table_name, *jam_obj["teams"]).pluck( + ["id", "name", "members", "repo"]).coerce_to("array") jam_obj["teams"] = self.db.run(query) + # Populate each team's members using the previously queried participant list + for team in jam_obj["teams"]: + team["members"] = [participants[user_id][0] for user_id in team["members"]] + return self.render( "main/jams/team_list.html", jam=jam_obj, |