API: Fix N+1 query in gift card list

This commit is contained in:
Raphael Michel
2023-10-17 14:55:42 +02:00
parent abfd8a7d86
commit 9299ac5813
2 changed files with 9 additions and 0 deletions

View File

@@ -116,6 +116,8 @@ class GiftCard(LoggedModel):
@property
def value(self):
if hasattr(self, 'cached_value'):
return self.cached_value or Decimal('0.00')
return self.transactions.aggregate(s=Sum('value'))['s'] or Decimal('0.00')
def accepted_by(self, organizer):