From c61f978c753712a50f1a2e1fd1da7973180ef817 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 7 Jan 2024 11:11:13 +0800 Subject: [PATCH] Improve caching --- equipment_tracker/transactions/serializers.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/equipment_tracker/transactions/serializers.py b/equipment_tracker/transactions/serializers.py index 4eb567f..7d6256f 100644 --- a/equipment_tracker/transactions/serializers.py +++ b/equipment_tracker/transactions/serializers.py @@ -191,6 +191,8 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer): # This updates the status field of all equipment instances in a single query EquipmentInstance.objects.filter( id__in=[equipment.id for equipment in equipments]).update(status='Available') + cache.delete('available_equipment_instances') + cache.delete('equipment_instances') return super().update(instance, validated_data) # For Approved transactions, @@ -208,6 +210,8 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer): # This updates the status field of all equipment instances in a single query EquipmentInstance.objects.filter( id__in=[equipment.id for equipment in equipments]).update(status='Available') + cache.delete('available_equipment_instances') + cache.delete('equipment_instances') return super().update(instance, validated_data) # If there are no issues and a transaction changes from Approved to Borrowed, label the selected equipment's statuses as Borrowed