Improve caching

This commit is contained in:
Keannu Bernasol 2024-01-07 11:07:48 +08:00
parent 10f3ece9b7
commit f418bc017d
2 changed files with 6 additions and 21 deletions

View file

@ -603,7 +603,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -631,7 +630,6 @@ paths:
required: true required: true
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'201': '201':
content: content:
@ -652,7 +650,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -676,7 +673,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -709,7 +705,6 @@ paths:
required: true required: true
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -741,7 +736,6 @@ paths:
$ref: '#/components/schemas/PatchedEquipmentInstance' $ref: '#/components/schemas/PatchedEquipmentInstance'
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -762,7 +756,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'204': '204':
description: No response body description: No response body
@ -773,7 +766,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -790,7 +782,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -807,7 +798,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -824,7 +814,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -852,7 +841,6 @@ paths:
required: true required: true
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'201': '201':
content: content:
@ -873,7 +861,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -897,7 +884,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -930,7 +916,6 @@ paths:
required: true required: true
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -962,7 +947,6 @@ paths:
$ref: '#/components/schemas/PatchedEquipment' $ref: '#/components/schemas/PatchedEquipment'
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -983,7 +967,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'204': '204':
description: No response body description: No response body
@ -994,7 +977,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -1011,7 +993,6 @@ paths:
- api - api
security: security:
- jwtAuth: [] - jwtAuth: []
- {}
responses: responses:
'200': '200':
content: content:
@ -1296,7 +1277,7 @@ components:
$ref: '#/components/schemas/StatusEnum' $ref: '#/components/schemas/StatusEnum'
remarks: remarks:
type: string type: string
maxLength: 512 nullable: true
last_updated: last_updated:
type: string type: string
format: date-time format: date-time
@ -1551,7 +1532,7 @@ components:
$ref: '#/components/schemas/StatusEnum' $ref: '#/components/schemas/StatusEnum'
remarks: remarks:
type: string type: string
maxLength: 512 nullable: true
last_updated: last_updated:
type: string type: string
format: date-time format: date-time

View file

@ -5,6 +5,7 @@ from .models import Transaction
from breakages.models import BreakageReport from breakages.models import BreakageReport
from accounts.models import CustomUser from accounts.models import CustomUser
from config.settings import DEBUG from config.settings import DEBUG
from django.core.cache import cache
class CustomUserSerializer(serializers.ModelSerializer): class CustomUserSerializer(serializers.ModelSerializer):
@ -128,6 +129,7 @@ class TransactionSerializer(serializers.HyperlinkedModelSerializer):
return transaction return transaction
def update(self, instance, validated_data): def update(self, instance, validated_data):
cache.delete('non_finalized_transactions')
user = self.context['request'].user user = self.context['request'].user
# User Validation # User Validation
@ -248,6 +250,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 the transaction changes from Returned: Pending Checking to With Breakages, we create a Breakage Report instance # If the transaction changes from Returned: Pending Checking to With Breakages, we create a Breakage Report instance