Enhance performance by prefetching more

This commit is contained in:
Joakim Hellsén 2026-04-10 22:32:38 +02:00
commit fb087a01c0
Signed by: Joakim Hellsén
SSH key fingerprint: SHA256:/9h/CsExpFp+PRhsfA0xznFx2CGfTT5R/kpuFfUgEQk
6 changed files with 104 additions and 12 deletions

View file

@ -292,10 +292,19 @@ class KickDropCampaign(auto_prefetch.Model):
def image_url(self) -> str:
"""Return the image URL for the campaign."""
# Image from first drop
if self.rewards.exists(): # pyright: ignore[reportAttributeAccessIssue]
first_reward: KickReward | None = self.rewards.first() # pyright: ignore[reportAttributeAccessIssue]
if first_reward and first_reward.image_url:
return first_reward.full_image_url
rewards_prefetched: list[KickReward] | None = getattr(
self,
"rewards_ordered",
None,
)
if rewards_prefetched is not None:
first_reward: KickReward | None = (
rewards_prefetched[0] if rewards_prefetched else None
)
else:
first_reward = self.rewards.first() # pyright: ignore[reportAttributeAccessIssue]
if first_reward and first_reward.image_url:
return first_reward.full_image_url
if self.category and self.category.image_url:
return self.category.image_url