Features: 1) Limit distinct values to 128 elements when count exceeds threshold; 2) Replace CategoryDetailSerializer with CategorySimpleSerializer in BrandDetailSerializer;
Fixes: 1) Add conditional caching based on user permissions; Extra: 1) Remove redundant condition on distinct values count; 2) Minor readability improvements within detail serializer logic;
This commit is contained in:
parent
f3ebf029ef
commit
86e2d787b1
1 changed files with 12 additions and 13 deletions
|
|
@ -89,20 +89,19 @@ class CategoryDetailSerializer(ModelSerializer):
|
||||||
.distinct()
|
.distinct()
|
||||||
)
|
)
|
||||||
|
|
||||||
distinct_vals_list = list(distinct_vals)
|
distinct_vals_list = list(distinct_vals)[0:128] if len(list(distinct_vals)) > 128 else list(distinct_vals)
|
||||||
|
|
||||||
if len(distinct_vals_list) <= 256:
|
filterable_results.append(
|
||||||
filterable_results.append(
|
{
|
||||||
{
|
"attribute_name": attr.name,
|
||||||
"attribute_name": attr.name,
|
"possible_values": distinct_vals_list,
|
||||||
"possible_values": distinct_vals_list,
|
"value_type": attr.value_type,
|
||||||
"value_type": attr.value_type,
|
}
|
||||||
}
|
)
|
||||||
)
|
|
||||||
else:
|
if not user.has_perm("view_attribute"):
|
||||||
continue
|
cache.set(f"{obj.uuid}_filterable_results", filterable_results, 86400)
|
||||||
|
|
||||||
cache.set(f"{obj.uuid}_filterable_results", filterable_results, 86400)
|
|
||||||
return filterable_results
|
return filterable_results
|
||||||
|
|
||||||
def get_children(self, obj) -> list[dict]:
|
def get_children(self, obj) -> list[dict]:
|
||||||
|
|
@ -123,7 +122,7 @@ class CategoryDetailSerializer(ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
class BrandDetailSerializer(ModelSerializer):
|
class BrandDetailSerializer(ModelSerializer):
|
||||||
categories = CategoryDetailSerializer(many=True)
|
categories = CategorySimpleSerializer(many=True)
|
||||||
small_logo = SerializerMethodField()
|
small_logo = SerializerMethodField()
|
||||||
big_logo = SerializerMethodField()
|
big_logo = SerializerMethodField()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue