Improve caching

This commit is contained in:
Keannu Bernasol 2024-01-07 11:11:13 +08:00
parent f418bc017d
commit c61f978c75

View file

@ -191,6 +191,8 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
# This updates the status field of all equipment instances in a single query # This updates the status field of all equipment instances in a single query
EquipmentInstance.objects.filter( EquipmentInstance.objects.filter(
id__in=[equipment.id for equipment in equipments]).update(status='Available') 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) return super().update(instance, validated_data)
# For Approved transactions, # For Approved transactions,
@ -208,6 +210,8 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
# This updates the status field of all equipment instances in a single query # This updates the status field of all equipment instances in a single query
EquipmentInstance.objects.filter( EquipmentInstance.objects.filter(
id__in=[equipment.id for equipment in equipments]).update(status='Available') 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) 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 # If there are no issues and a transaction changes from Approved to Borrowed, label the selected equipment's statuses as Borrowed