From 6f9265a7112e561926a45f06ae33ec185b0b4ca9 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 5 Sep 2022 09:01:04 +0200 Subject: [PATCH] Revert "testing on prod" This reverts commit e1a71486f71f1f65894e57de196f3a52532d0ee6. --- files/routes/users.py | 76 ++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/files/routes/users.py b/files/routes/users.py index bf236e832..7bbf2f6e3 100644 --- a/files/routes/users.py +++ b/files/routes/users.py @@ -19,6 +19,45 @@ from sys import stdout import os +def leaderboard_thread(): + global users9, users9_25, users13, users13_25 + + db = db_session() + + 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).filter(User.id.in_(votes3.keys())).all() + users9 = [] + for user in users8: users9.append((user, votes3[user.id])) + users9 = sorted(users9, key=lambda x: x[1], reverse=True) + users9_25 = users9[:25] + + 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, votes3[user.id]-user.post_count-user.comment_count)) + users13 = sorted(users13, key=lambda x: x[1], reverse=True) + users13_25 = users13[:25] + + db.close() + stdout.flush() + +gevent.spawn(leaderboard_thread()) + + + + + + + + + + + @app.get("/@/upvoters//posts") @auth_required def upvoters_posts(v, username, uid): @@ -495,43 +534,6 @@ 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).filter(User.id.in_(votes3.keys())).all() - users9 = [] - for user in users8: users9.append((user, votes3[user.id])) - users9 = sorted(users9, key=lambda x: x[1], reverse=True) - users9_25 = users9[:25] - - 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, votes3[user.id]-user.post_count-user.comment_count)) - users13 = sorted(users13, key=lambda x: x[1], reverse=True) - users13_25 = users13 - - - - - - - - - - - - - - try: pos9 = [x[0].id for x in users9].index(v.id) pos9 = (pos9+1, users9[pos9][1])