diff --git a/files/routes/votes.py b/files/routes/votes.py index af1184972..1ffa50389 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -56,7 +56,6 @@ def admin_vote_info_get(v): @app.post("/vote/post//") -@limiter.limit("1/second") @auth_required @validate_formkey def api_vote_post(post_id, new, v): @@ -101,15 +100,16 @@ def api_vote_post(post_id, new, v): ) g.db.add(vote) - g.db.flush() - post.upvotes = g.db.query(Vote.id).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=1).count() - post.downvotes = g.db.query(Vote.id).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=-1).count() - g.db.add(post) - g.db.commit() + try: + g.db.flush() + post.upvotes = g.db.query(Vote.id).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=1).count() + post.downvotes = g.db.query(Vote.id).options(lazyload('*')).filter_by(submission_id=post.id, vote_type=-1).count() + g.db.add(post) + g.db.commit() + except: g.db.rollback() return "", 204 @app.post("/vote/comment//") -@limiter.limit("1/second") @auth_required @validate_formkey def api_vote_comment(comment_id, new, v): @@ -159,16 +159,17 @@ def api_vote_comment(comment_id, new, v): g.db.add(vote) - g.db.flush() - comment.upvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count() - comment.downvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=-1).count() - g.db.add(comment) - g.db.commit() + try: + g.db.flush() + comment.upvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count() + comment.downvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=-1).count() + g.db.add(comment) + g.db.commit() + except: g.db.rollback() return "", 204 @app.post("/vote/poll/") -@limiter.limit("1/second") @auth_required def api_vote_poll(comment_id, v): @@ -193,8 +194,10 @@ def api_vote_poll(comment_id, v): vote = CommentVote(user_id=v.id, vote_type=new, comment_id=comment.id) g.db.add(vote) - g.db.flush() - comment.upvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count() - g.db.add(comment) - g.db.commit() + try: + g.db.flush() + comment.upvotes = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(comment_id=comment.id, vote_type=1).count() + g.db.add(comment) + g.db.commit() + except: g.db.rollback() return "", 204 \ No newline at end of file