From 008ab92f95df777daad4b43d1d47011a031f873e Mon Sep 17 00:00:00 2001 From: Egor fureunoir Gorbunov Date: Mon, 26 May 2025 22:16:32 +0300 Subject: [PATCH] Features: 1) Filter recently viewed products by active status in serializer; Fixes: 1) Correct default value in `recently_viewed` property to handle cache miss; Extra: 1) Inline simplification of serializer logic for recently viewed products. --- vibes_auth/models.py | 2 +- vibes_auth/serializers.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/vibes_auth/models.py b/vibes_auth/models.py index 3a02a890..464a37b9 100644 --- a/vibes_auth/models.py +++ b/vibes_auth/models.py @@ -87,7 +87,7 @@ class User(AbstractUser, NiceModel): @property def recently_viewed(self): - return [] or cache.get(f"user_{self.uuid}_rv") + return cache.get(f"user_{self.uuid}_rv", []) def check_token(self, token): return str(token) == str(self.activation_token) diff --git a/vibes_auth/serializers.py b/vibes_auth/serializers.py index 03470884..847b767e 100644 --- a/vibes_auth/serializers.py +++ b/vibes_auth/serializers.py @@ -94,9 +94,8 @@ class UserSerializer(ModelSerializer): Returns a list of serialized ProductSimpleSerializer representations for the UUIDs in obj.recently_viewed. """ - queryset = Product.objects.filter(uuid__in=obj.recently_viewed) - serializer = ProductSimpleSerializer(queryset, many=True) - return serializer.data + return ProductSimpleSerializer(Product.objects.filter(uuid__in=obj.recently_viewed, is_active=True), + many=True).data class TokenObtainSerializer(Serializer):