diff --git a/files/routes/users.py b/files/routes/users.py index 2e67b4c3f..1bdcd16e0 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -324,37 +324,37 @@ def leaderboard(v): sq = g.db.query(User.id, func.rank().over(order_by=User.coins.desc()).label("rank")).subquery() pos1 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] - users2 = users.order_by(User.stored_subscriber_count.desc()).all() - pos2 = users2.index(v) - users2 = users2[:25] + users2 = users.order_by(User.stored_subscriber_count.desc()).limit(25).all() + sq = g.db.query(User.id, func.rank().over(order_by=User.stored_subscriber_count.desc()).label("rank")).subquery() + pos2 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] - users3 = users.order_by(User.post_count.desc()).all() - pos3 = users3.index(v) - users3 = users3[:25] + users3 = users.order_by(User.post_count.desc()).limit(25).all() + sq = g.db.query(User.id, func.rank().over(order_by=User.post_count.desc()).label("rank")).subquery() + pos3 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] - users4 = users.order_by(User.comment_count.desc()).all() - pos4 = users4.index(v) - users4 = users4[:25] + users4 = users.order_by(User.comment_count.desc()).limit(25).all() + sq = g.db.query(User.id, func.rank().over(order_by=User.comment_count.desc()).label("rank")).subquery() + pos4 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] - users5 = users.order_by(User.received_award_count.desc()).all() - pos5 = users5.index(v) - users5 = users5[:25] + users5 = users.order_by(User.received_award_count.desc()).limit(25).all() + sq = g.db.query(User.id, func.rank().over(order_by=User.received_award_count.desc()).label("rank")).subquery() + pos5 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] if request.host == 'pcmemes.net': - users6 = users.order_by(User.basedcount.desc()).all() - pos6 = users6.index(v) - users6 = users6[:25] + users6 = users.order_by(User.basedcount.desc()).limit(25).all() + sq = g.db.query(User.id, func.rank().over(order_by=User.basedcount.desc()).label("rank")).subquery() + pos6 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] else: users6 = None pos6 = None - users7 = users.order_by(User.coins_spent.desc()).all() - pos7 = users7.index(v) - users7 = users7[:25] + users7 = users.order_by(User.coins_spent.desc()).limit(25).all() + sq = g.db.query(User.id, func.rank().over(order_by=User.coins_spent.desc()).label("rank")).subquery() + pos7 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] - users10 = users.order_by(User.truecoins.desc()).all() - pos10 = users10.index(v) - users10 = users10[:25] + users10 = users.order_by(User.truecoins.desc()).limit(25).all() + sq = g.db.query(User.id, func.rank().over(order_by=User.truecoins.desc()).label("rank")).subquery() + pos10 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] return render_template("leaderboard.html", v=v, users1=users1, pos1=pos1, users2=users2, pos2=pos2, users3=users3, pos3=pos3, users4=users4, pos4=pos4, users5=users5, pos5=pos5, users6=users6, pos6=pos6, users7=users7, pos7=pos7, users9=users9, users10=users10, pos10=pos10, users12=users12, users13=users13, users15=users15)