Only grab fields that are needed

This commit is contained in:
2024-07-04 00:27:18 +02:00
parent 344a656056
commit cea4d3d913
2 changed files with 25 additions and 7 deletions

View File

@ -24,7 +24,7 @@
<div class="card-body card-bottom">
{% for drop in campaign.drops %}
<div class="col-6 col-md-4 d-flex align-items-center mb-2 position-relative">
<img src="{{ drop.image_url|default:'https://static-cdn.jtvnw.net/twitch-quests-assets/CAMPAIGN/default.png' }}"
<img src="{{ drop.image_url }}"
alt="{{ drop.name }} drop image"
class="img-fluid rounded me-3"
height="50"

View File

@ -85,20 +85,38 @@ def index(request: HttpRequest) -> 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,
),