Features: 1) None;
Fixes: 1) Correct conditional check for cached filterable results to handle `None` values; 2) Remove unnecessary permission checks for attribute filtering; Extra: 1) Update cache expiry time from 86400 seconds to 3600 seconds.
This commit is contained in:
parent
c78e0e8137
commit
f67319ba5a
1 changed files with 3 additions and 10 deletions
|
|
@ -76,16 +76,10 @@ class CategoryDetailSerializer(ModelSerializer):
|
|||
def get_filterable_attributes(self, obj: Category) -> list[dict]:
|
||||
cache_key = f"{obj.uuid}_filterable_results"
|
||||
filterable_results = cache.get(cache_key)
|
||||
if filterable_results:
|
||||
if filterable_results is not None:
|
||||
return filterable_results
|
||||
|
||||
request = self.context.get("request")
|
||||
user = getattr(request, "user", AnonymousUser())
|
||||
attrs_qs = (
|
||||
obj.attributes.filter(is_filterable=True)
|
||||
if user.has_perm("view_attribute")
|
||||
else obj.attributes.filter(is_active=True, is_filterable=True)
|
||||
)
|
||||
attrs_qs = obj.attributes.filter(is_active=True, is_filterable=True)
|
||||
attributes = list(attrs_qs)
|
||||
|
||||
attr_ids = [a.id for a in attributes]
|
||||
|
|
@ -116,8 +110,7 @@ class CategoryDetailSerializer(ModelSerializer):
|
|||
}
|
||||
)
|
||||
|
||||
if not user.has_perm("view_attribute"):
|
||||
cache.set(cache_key, filterable_results, 86400)
|
||||
cache.set(cache_key, filterable_results, 3600)
|
||||
|
||||
return filterable_results
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue