Skip to content

Commit

Permalink
Fix getting the list of available teams per organization
Browse files Browse the repository at this point in the history
The problem comes from the fact that `teamname` is a runtime property of
the `Team` class and not an actual database  field.
In addition we were using `Team.object.values()` which returns an
`Iterable[dict]`, instead of `Iterable[Team]`. So even if it returned
the right type, it would have been terribly slow, due to N+1 situation.
  • Loading branch information
suricactus committed Jan 7, 2025
1 parent 7fb503f commit 71ff81c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions docker-app/qfieldcloud/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,13 @@ def get_members(self, obj):

def get_teams(self, obj: Organization) -> list[str]:
"""Implementation of `SerializerMethodField` for `teams`. Returns list of team names."""
return [
t.teamname
for t in Team.objects.filter(team_organization=obj).values("username")
]
team_qs = (
Team.objects.filter(team_organization=obj)
.select_related("team_organization")
.only("username", "team_organization__username")
)

return [t.teamname for t in team_qs]

def get_avatar_url(self, obj):
return get_avatar_url(obj)
Expand Down

0 comments on commit 71ff81c

Please sign in to comment.