From 2c8af476c89dcab568e38c4788a565a270558bce Mon Sep 17 00:00:00 2001 From: ZUS666 Date: Tue, 31 Oct 2023 16:01:31 +0500 Subject: [PATCH 1/3] invalid cache --- api_spot/api/views/add_spots.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api_spot/api/views/add_spots.py b/api_spot/api/views/add_spots.py index 6a6cb5e5..f6e18130 100644 --- a/api_spot/api/views/add_spots.py +++ b/api_spot/api/views/add_spots.py @@ -11,6 +11,7 @@ from api.exceptions import AddSpotsError from api.serializers import AddSpotsSerializer from spots.models import Location, Spot, SpotEquipment +from spots.services import delete_location_cache_in_spot @extend_schema( @@ -56,6 +57,7 @@ def post(self, request, location_id, *args, **kwargs): ) for sp in new_spots for eq in equipments ] SpotEquipment.objects.bulk_create(bulk2) + delete_location_cache_in_spot(location_id) return Response( {'count_created_spots': len(new_spots)}, status=status.HTTP_201_CREATED From 6fed54cfd21f6a30280e7c94a9058e5353dbfe4e Mon Sep 17 00:00:00 2001 From: ZUS666 Date: Tue, 31 Oct 2023 17:52:20 +0500 Subject: [PATCH 2/3] signal --- api_spot/spots/apps.py | 3 +++ api_spot/spots/models/spot.py | 5 +---- api_spot/spots/siglnals.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 api_spot/spots/siglnals.py diff --git a/api_spot/spots/apps.py b/api_spot/spots/apps.py index 5f67cdf5..8daa752a 100644 --- a/api_spot/spots/apps.py +++ b/api_spot/spots/apps.py @@ -3,3 +3,6 @@ class SpotsConfig(AppConfig): name = 'spots' + + def ready(self) -> None: + from spots import siglnals # noqa: F401 diff --git a/api_spot/spots/models/spot.py b/api_spot/spots/models/spot.py index db8d5c55..6594ded1 100644 --- a/api_spot/spots/models/spot.py +++ b/api_spot/spots/models/spot.py @@ -57,9 +57,6 @@ def __str__(self): return f'{self.name} в {self.location}' def save(self, *args, **kwargs): + print('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA') delete_location_cache_in_spot(self.location_id) return super().save(*args, **kwargs) - - def delete(self, *args, **kwargs): - delete_location_cache_in_spot(self.location_id) - return super().delete(*args, **kwargs) diff --git a/api_spot/spots/siglnals.py b/api_spot/spots/siglnals.py new file mode 100644 index 00000000..8cd5f44a --- /dev/null +++ b/api_spot/spots/siglnals.py @@ -0,0 +1,10 @@ +from django.db.models.signals import post_delete +from django.dispatch import receiver + +from spots.models import Spot +from spots.services import delete_location_cache_in_spot + + +@receiver(post_delete, sender=Spot) +def delete_cache_spots_signal(sender, instance, *args, **kwargs): + delete_location_cache_in_spot(instance.location.id) From 43c3a651413f9c9a5f2a79fd4697c53dcd544687 Mon Sep 17 00:00:00 2001 From: ZUS666 Date: Tue, 31 Oct 2023 17:59:07 +0500 Subject: [PATCH 3/3] del print --- api_spot/spots/models/spot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/api_spot/spots/models/spot.py b/api_spot/spots/models/spot.py index 6594ded1..e8ae3d6d 100644 --- a/api_spot/spots/models/spot.py +++ b/api_spot/spots/models/spot.py @@ -57,6 +57,5 @@ def __str__(self): return f'{self.name} в {self.location}' def save(self, *args, **kwargs): - print('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA') delete_location_cache_in_spot(self.location_id) return super().save(*args, **kwargs)