From d2661bd222a8cdfcc9d4817426440564c6e30ae7 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Mon, 26 Jul 2021 22:01:39 +0200 Subject: [PATCH] fdfd --- drama/routes/votes.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/drama/routes/votes.py b/drama/routes/votes.py index 6df308f7c4..3098dcf233 100644 --- a/drama/routes/votes.py +++ b/drama/routes/votes.py @@ -103,6 +103,7 @@ def api_vote_post(post_id, new, v): g.db.add(post.author) existing.vote_type = new g.db.add(existing) + g.db.commit() else: if new != 0: post.author.dramacoins += 1 @@ -112,10 +113,8 @@ def api_vote_post(post_id, new, v): submission_id=base36decode(post_id), app_id=v.client.application.id if v.client else None ) - g.db.add(vote) - - g.db.flush() + g.db.commit() post.upvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=1).count() post.downvotes = g.db.query(Vote).filter_by(submission_id=post.id, vote_type=-1).count() @@ -152,6 +151,7 @@ def api_vote_comment(comment_id, new, v): g.db.add(comment.author) existing.vote_type = new g.db.add(existing) + g.db.commit() else: if new != 0: comment.author.dramacoins += 1 @@ -163,10 +163,7 @@ def api_vote_comment(comment_id, new, v): ) g.db.add(vote) - try: - g.db.flush() - except: - return jsonify({"error":"Vote already exists."}), 422 + g.db.commit() comment.upvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=1).count() comment.downvotes = g.db.query(CommentVote).filter_by(comment_id=comment.id, vote_type=-1).count()