From fdc8a7847291f8553f4edbb54e152ff26b2af67f Mon Sep 17 00:00:00 2001 From: TLSM Date: Fri, 16 Sep 2022 15:28:24 -0400 Subject: [PATCH] Fix leaderboard for winnings change. --- files/classes/user.py | 2 +- files/routes/users.py | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 1b19ea8cd..f64b5cecc 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -933,4 +933,4 @@ class User(Base): from_casino = g.db.query(func.sum(Casino_Game.winnings)).filter(Casino_Game.user_id == self.id).one()[0] from_casino_value = from_casino or 0 - return from_casino_value + self.total_lottery_winnings \ No newline at end of file + return from_casino_value + self.total_lottery_winnings diff --git a/files/routes/users.py b/files/routes/users.py index 071db4ce8..db6daa1a5 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -585,18 +585,19 @@ def leaderboard(v): pos13 = (pos13+1, users13[pos13][1]) except: pos13 = (len(users13)+1, 0) - users14 = users.order_by(User.winnings.desc()).limit(25).all() + winnings_sq = g.db.query(Casino_Game.user_id, func.sum(Casino_Game.winnings)).group_by(Casino_Game.user_id).subquery() + users14 = g.db.query(User).join(winnings_sq, winnings_sq.c.user_id == User.id).order_by(winnings_sq.c.sum.desc()).limit(25).all() if v in users14: pos14 = None else: - sq = g.db.query(User.id, func.rank().over(order_by=User.winnings.desc()).label("rank")).subquery() + sq = g.db.query(User.id, func.rank().over(order_by=winnings_sq.c.sum.desc()).label("rank")).join(winnings_sq, winnings_sq.c.user_id == User.id).subquery() pos14 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] - users15 = users.order_by(User.winnings).limit(25).all() + users15 = g.db.query(User).join(winnings_sq, winnings_sq.c.user_id == User.id).order_by(winnings_sq.c.sum.asc()).limit(25).all() if v in users15: pos15 = None else: - sq = g.db.query(User.id, func.rank().over(order_by=User.winnings).label("rank")).subquery() + sq = g.db.query(User.id, func.rank().over(order_by=winnings_sq.c.sum.asc()).label("rank")).join(winnings_sq, winnings_sq.c.user_id == User.id).subquery() pos15 = g.db.query(sq.c.id, sq.c.rank).filter(sq.c.id == v.id).limit(1).one()[1] sq = g.db.query(UserBlock.target_id, func.count(UserBlock.target_id).label("count")).group_by(UserBlock.target_id).subquery()