Skip to content

Commit 68a3d1f

Browse files
committed
Refactor catalog category sorting to prioritize product counts
- Updated the return statement in the catalog_categories function to sort categories based on the total product count in their subcategories. - Enhanced readability by using sorted() with a custom key for improved clarity in the sorting logic.
1 parent 81b79b1 commit 68a3d1f

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

app/api/resources.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,11 @@ def catalog_categories():
205205
"product_count": cnt,
206206
})
207207

208-
return [
209-
{"category": cat, "subcategories": subs}
210-
for cat, subs in sorted(grouped.items())
211-
]
208+
return sorted(
209+
[{"category": cat, "subcategories": subs} for cat, subs in grouped.items()],
210+
key=lambda g: sum(s["product_count"] for s in g["subcategories"]),
211+
reverse=True,
212+
)
212213

213214

214215
@route.get("/catalog/browse/{slug}")

0 commit comments

Comments
 (0)