Skip to content

Commit 5fcbd72

Browse files
committed
Optimize teams list by pre-fetching city relationship
1 parent c6f43a6 commit 5fcbd72

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

get_together/views/teams.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from django.utils.translation import ugettext_lazy as _
1313

1414
import simplejson
15+
1516
from accounts.models import EmailRecord
1617
from events import location
1718
from events.forms import (
@@ -47,7 +48,7 @@ def teams_list(request, *args, **kwargs):
4748
if not request.user.is_authenticated:
4849
return redirect("all-teams")
4950

50-
teams = request.user.profile.memberships.all().distinct()
51+
teams = request.user.profile.memberships.all().select_related("city").distinct()
5152
geo_ip = location.get_geoip(request)
5253
context = {
5354
"active": "my",
@@ -61,7 +62,7 @@ def teams_list(request, *args, **kwargs):
6162
def teams_list_all(request, *args, **kwargs):
6263
teams = [
6364
team
64-
for team in Team.objects.all()
65+
for team in Team.objects.all().select_related("city")
6566
if team.access == Team.PUBLIC
6667
or (team.access == Team.PRIVATE and request.user.profile.is_in_team(team))
6768
]

0 commit comments

Comments
 (0)