From e98119e923fb3a43b33a85dc5b4b0b176d3ecb18 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Wed, 1 Dec 2021 03:10:36 +0200 Subject: [PATCH] gfg --- files/routes/votes.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/files/routes/votes.py b/files/routes/votes.py index e85142e3a..c6e3ae65e 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -115,12 +115,14 @@ def api_vote_post(post_id, new, v): g.db.add(post) cache.delete_memoized(frontlist) - g.db.flush() - post.upvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=1).count() - post.downvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=-1).count() - post.realupvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=1, real=True).count() - g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=1, real=False).count() - g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=-1, real=True).count() + g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=-1, real=False).count() - g.db.add(post) - g.db.commit() + try: + g.db.flush() + post.upvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=1).count() + post.downvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=-1).count() + post.realupvotes = g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=1, real=True).count() - g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=1, real=False).count() - g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=-1, real=True).count() + g.db.query(Vote.id).filter_by(submission_id=post.id, vote_type=-1, real=False).count() + g.db.add(post) + g.db.commit() + except: g.db.rollback() return "", 204 @app.post("/vote/comment//") @@ -181,12 +183,14 @@ def api_vote_comment(comment_id, new, v): comment.is_pinned = None g.db.add(comment) - g.db.flush() - comment.upvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=1).count() - comment.downvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=-1).count() - comment.realupvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, CommentVote_type=1, real=True).count() - g.db.query(CommentVote.id).filter_by(comment_id=comment.id, CommentVote_type=1, real=False).count() - g.db.query(CommentVote.id).filter_by(comment_id=comment.id, CommentVote_type=-1, real=True).count() + g.db.query(CommentVote.id).filter_by(comment_id=comment.id, CommentVote_type=-1, real=False).count() - g.db.add(comment) - g.db.commit() + try: + g.db.flush() + comment.upvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=1).count() + comment.downvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=-1).count() + comment.realupvotes = g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=1, real=True).count() - g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=1, real=False).count() - g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=-1, real=True).count() + g.db.query(CommentVote.id).filter_by(comment_id=comment.id, vote_type=-1, real=False).count() + g.db.add(comment) + g.db.commit() + except: g.db.rollback() return "", 204