From cea4d3d913450dc89525567403729ea7d08f7c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20Hells=C3=A9n?= Date: Thu, 4 Jul 2024 00:27:18 +0200 Subject: [PATCH] Only grab fields that are needed --- core/templates/index.html | 2 +- core/views.py | 30 ++++++++++++++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/core/templates/index.html b/core/templates/index.html index ce37d90..04a9681 100644 --- a/core/templates/index.html +++ b/core/templates/index.html @@ -24,7 +24,7 @@
{% for drop in campaign.drops %}
- {{ drop.name }} drop image HttpResponse: """ list_of_games: list[GameContext] = [] - for game in Game.objects.all(): + for game in Game.objects.all().only("id", "image_url", "display_name", "slug"): campaigns: list[CampaignContext] = [] - for campaign in DropCampaign.objects.filter(game=game, status="ACTIVE"): + for campaign in DropCampaign.objects.filter(game=game, status="ACTIVE").only( + "id", + "name", + "image_url", + "status", + "account_link_url", + "description", + "details_url", + "start_at", + "end_at", + ): drops: list[DropContext] = [] - drop: TimeBasedDrop - for drop in campaign.time_based_drops.all(): + for drop in campaign.time_based_drops.all().only( + "id", + "name", + "required_minutes_watched", + "required_subs", + ): benefit: DropBenefit | None = drop.benefits.first() + image_asset_url: str = ( + benefit.image_asset_url + if benefit + else "https://static-cdn.jtvnw.net/twitch-quests-assets/CAMPAIGN/default.png" + ) drops.append( DropContext( drops_id=drop.id, - image_url=benefit.image_asset_url if benefit else None, + image_url=image_asset_url, name=drop.name, - limit=None, required_minutes_watched=drop.required_minutes_watched, required_subs=drop.required_subs, ),