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.
This commit is contained in:
Egor Pavlovich Gorbunov 2025-05-26 22:16:32 +03:00
parent ecad0561a5
commit 008ab92f95
2 changed files with 3 additions and 4 deletions

View file

@ -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)

View file

@ -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):