fix hat ordering in a more performant way
parent
58a84e11fe
commit
b0eea9b223
|
@ -37,12 +37,12 @@ def hats(v:User):
|
||||||
|
|
||||||
hats = hats.order_by(key).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
|
hats = hats.order_by(key).offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
|
||||||
elif sort == "owners":
|
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':
|
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:
|
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)
|
firstrange = PAGE_SIZE * (page - 1)
|
||||||
secondrange = firstrange + PAGE_SIZE
|
secondrange = firstrange + PAGE_SIZE
|
||||||
|
|
Loading…
Reference in New Issue