remotes/1693045480750635534/spooky-22
Aevann1 2021-12-01 03:10:36 +02:00
parent 1594c15836
commit 36cfdd672c
1 changed files with 16 additions and 12 deletions

View File

@ -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/<comment_id>/<new>")
@ -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