Move organization detail queryset optimizations to model; add tests for organization detail queryset
All checks were successful
Deploy to Server / deploy (push) Successful in 30s

This commit is contained in:
Joakim Hellsén 2026-04-12 05:19:24 +02:00
commit 1790bac2e0
Signed by: Joakim Hellsén
SSH key fingerprint: SHA256:/9h/CsExpFp+PRhsfA0xznFx2CGfTT5R/kpuFfUgEQk
3 changed files with 96 additions and 11 deletions

View file

@ -75,6 +75,27 @@ class Organization(auto_prefetch.Model):
"""Return organizations with only fields needed by the org list page."""
return cls.objects.only("twitch_id", "name").order_by("name")
@classmethod
def for_detail_view(cls) -> models.QuerySet[Organization]:
"""Return organizations with only fields and relations needed by detail page."""
return cls.objects.only(
"twitch_id",
"name",
"added_at",
"updated_at",
).prefetch_related(
models.Prefetch(
"games",
queryset=Game.objects.only(
"twitch_id",
"name",
"display_name",
"slug",
).order_by("display_name"),
to_attr="games_for_detail",
),
)
def feed_description(self: Organization) -> str:
"""Return a description of the organization for RSS feeds."""
name: str = self.name or "Unknown Organization"