mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2025-04-27 10:11:24 +08:00
Improve query caching
This commit is contained in:
parent
8e43e06ec2
commit
e482979d20
4 changed files with 28 additions and 6 deletions
|
@ -99,12 +99,12 @@ class AvailableEquipmentInstanceViewSet(generics.ListAPIView):
|
|||
# Get all equipment instances associated with non-finalized transactions
|
||||
non_finalized_equipments = EquipmentInstance.objects.filter(
|
||||
transaction__in=non_finalized_transactions
|
||||
).prefetch_related('equipment')
|
||||
).order_by('id').prefetch_related('equipment')
|
||||
|
||||
# Get all equipment instances which are not associated with non-finalized transactions
|
||||
queryset = EquipmentInstance.objects.exclude(
|
||||
id__in=non_finalized_equipments.values_list(
|
||||
'id', flat=True).order_by('id')
|
||||
'id', flat=True)
|
||||
)
|
||||
cache.set(key, queryset, timeout=60*60*24)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue