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]:
|
def get_filterable_attributes(self, obj: Category) -> list[dict]:
|
||||||
cache_key = f"{obj.uuid}_filterable_results"
|
cache_key = f"{obj.uuid}_filterable_results"
|
||||||
filterable_results = cache.get(cache_key)
|
filterable_results = cache.get(cache_key)
|
||||||
if filterable_results:
|
if filterable_results is not None:
|
||||||
return filterable_results
|
return filterable_results
|
||||||
|
|
||||||
request = self.context.get("request")
|
attrs_qs = obj.attributes.filter(is_active=True, is_filterable=True)
|
||||||
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)
|
|
||||||
)
|
|
||||||
attributes = list(attrs_qs)
|
attributes = list(attrs_qs)
|
||||||
|
|
||||||
attr_ids = [a.id for a in attributes]
|
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, 3600)
|
||||||
cache.set(cache_key, filterable_results, 86400)
|
|
||||||
|
|
||||||
return filterable_results
|
return filterable_results
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue