From b0eea9b223b7119868b631504094bc103b8272fa Mon Sep 17 00:00:00 2001 From: Aevann Date: Fri, 5 May 2023 09:37:58 +0300 Subject: [PATCH] fix hat ordering in a more performant way --- files/routes/hats.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/files/routes/hats.py b/files/routes/hats.py index 789c9f9ce..d88d9cdd2 100644 --- a/files/routes/hats.py +++ b/files/routes/hats.py @@ -37,12 +37,12 @@ def hats(v:User): hats = hats.order_by(key).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all() elif sort == "owners": - hat_count = [x[0] for x in g.db.query(Hat.hat_id).group_by(Hat.hat_id).order_by(func.count(Hat.hat_id).desc()).all()] + hat_count = {x[0]:x[1] for x in g.db.query(Hat.hat_id, func.count(Hat.hat_id)).group_by(Hat.hat_id).all()} if SITE == 'rdrama.net': - hats = sorted(hats.all(), key=lambda x: hat_count.index(x[0].id) if x[0].id in hat_count else 0) + hats = sorted(hats.all(), key=lambda x: hat_count[x[0].id] if x[0].id in hat_count else 0, reverse=True) else: - hats = sorted(hats.all(), key=lambda x: hat_count.index(x.id) if x.id in hat_count else 0) + hats = sorted(hats.all(), key=lambda x: hat_count[x.id] if x.id in hat_count else 0, reverse=True) firstrange = PAGE_SIZE * (page - 1) secondrange = firstrange + PAGE_SIZE