From e071f9c81bd32acb2785161a19d4847afdc36845 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Thu, 6 Oct 2022 10:23:29 +0200 Subject: [PATCH] remove leaderboard_thread --- files/routes/users.py | 57 ++++++-------------------------- files/templates/leaderboard.html | 35 -------------------- 2 files changed, 11 insertions(+), 81 deletions(-) diff --git a/files/routes/users.py b/files/routes/users.py index 79d604e9c..83f5ac556 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -21,42 +21,6 @@ import os import json from .login import check_for_alts -def leaderboard_thread(): - db = db_session() - - global users9, users9_1, users9_2 - votes1 = db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote).filter(Vote.vote_type==-1).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).all() - votes2 = db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote).filter(CommentVote.vote_type==-1).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all() - votes3 = Counter(dict(votes1)) + Counter(dict(votes2)) - users8 = db.query(User.id).filter(User.id.in_(votes3.keys())).all() - users9 = [] - for user in users8: - users9.append((user.id, votes3[user.id])) - if not users9: users9 = [(None,None)] - users9 = sorted(users9, key=lambda x: x[1], reverse=True) - users9_1, users9_2 = zip(*users9[:25]) - - global users13, users13_1, users13_2 - votes1 = db.query(Vote.user_id, func.count(Vote.user_id)).filter(Vote.vote_type==1).group_by(Vote.user_id).order_by(func.count(Vote.user_id).desc()).all() - votes2 = db.query(CommentVote.user_id, func.count(CommentVote.user_id)).filter(CommentVote.vote_type==1).group_by(CommentVote.user_id).order_by(func.count(CommentVote.user_id).desc()).all() - votes3 = Counter(dict(votes1)) + Counter(dict(votes2)) - users14 = db.query(User).filter(User.id.in_(votes3.keys())).all() - users13 = [] - for user in users14: - users13.append((user.id, votes3[user.id]-user.post_count-user.comment_count)) - if not users13: users13 = [(None,None)] - users13 = sorted(users13, key=lambda x: x[1], reverse=True) - users13_1, users13_2 = zip(*users13[:25]) - - db.close() - stdout.flush() - - -gevent.spawn(leaderboard_thread) - - - - @app.get("/@/upvoters//posts") @auth_required @@ -590,6 +554,16 @@ def leaderboard(v): 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] + votes1 = db.query(Submission.author_id, func.count(Submission.author_id)).join(Vote).filter(Vote.vote_type==-1).group_by(Submission.author_id).order_by(func.count(Submission.author_id).desc()).all() + votes2 = db.query(Comment.author_id, func.count(Comment.author_id)).join(CommentVote).filter(CommentVote.vote_type==-1).group_by(Comment.author_id).order_by(func.count(Comment.author_id).desc()).all() + votes3 = Counter(dict(votes1)) + Counter(dict(votes2)) + users8 = db.query(User.id).filter(User.id.in_(votes3.keys())).all() + users9 = [] + for user in users8: + users9.append((user.id, votes3[user.id])) + if not users9: users9 = [(None,None)] + users9 = sorted(users9, key=lambda x: x[1], reverse=True) + users9_1, users9_2 = zip(*users9[:25]) users9_accs = g.db.query(User).filter(User.id.in_(users9_1)).all() users9_accs = sorted(users9_accs, key=lambda x: users9_1.index(x.id)) @@ -624,14 +598,6 @@ def leaderboard(v): users12 = None pos12 = None - users13_accs = g.db.query(User).filter(User.id.in_(users13_1)).all() - users13_accs = sorted(users13_accs, key=lambda x: users13_1.index(x.id)) - users13_accs = zip(users13_accs, users13_2) - try: - pos13 = [x[0] for x in users13].index(v.id) - pos13 = (pos13+1, users13[pos13][1]) - except: pos13 = (len(users13)+1, 0) - # 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: @@ -669,8 +635,7 @@ def leaderboard(v): 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, users7=users7, pos7=pos7, users9=users9_accs, pos9=pos9, - users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12, - users13=users13_accs, pos13=pos13, users16=users16, pos16=pos16, users17=users17, pos17=pos17, users18=users18, pos18=pos18) + users10=users10, pos10=pos10, users11=users11, pos11=pos11, users12=users12, pos12=pos12, users16=users16, pos16=pos16, users17=users17, pos17=pos17, users18=users18, pos18=pos18) @app.get("//css") def get_css(id): diff --git a/files/templates/leaderboard.html b/files/templates/leaderboard.html index 9381822b7..554e65fcd 100644 --- a/files/templates/leaderboard.html +++ b/files/templates/leaderboard.html @@ -15,7 +15,6 @@ DownvotesBadges • {% if users12 %}Marseys • {% endif %} - {% if users13 %}Upvotes Given • {% endif %} BlockedOwned HatsDesigned Hats @@ -336,40 +335,6 @@ {% endif %} -{% if users13 %} -
Top 25 by upvotes given
- -
- - - - - - - - - {% for user, num in users13 %} - - - - - - {% endfor %} - {% if pos13 and (pos13[0] > 25 or not pos13[1]) %} - - - - - - {% endif %} - -
#NameUpvotes
{{loop.index}}{% include "user_in_table.html" %}{{"{:,}".format(num)}}
{{pos13[0]}} - {% with user=v %} - {% include "user_in_table.html" %} - {% endwith %} - {{"{:,}".format(pos13[1])}}
-{% endif %} -
Top 25 Most Blocked