gf
This commit is contained in:
parent
dd39711709
commit
f90db38c08
4 changed files with 28 additions and 38 deletions
|
@ -9,10 +9,9 @@ class Vote(Base):
|
|||
|
||||
__tablename__ = "votes"
|
||||
|
||||
id = Column(Integer, primary_key=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"))
|
||||
submission_id = Column(Integer, ForeignKey("submissions.id"), primary_key=True)
|
||||
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
||||
vote_type = Column(Integer)
|
||||
submission_id = Column(Integer, ForeignKey("submissions.id"))
|
||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||
real = Column(Boolean, default=True)
|
||||
created_utc = Column(Integer)
|
||||
|
|
|
@ -1008,8 +1008,7 @@ def save_comment(cid, v):
|
|||
new_save=CommentSaveRelationship(user_id=v.id, comment_id=comment.id)
|
||||
g.db.add(new_save)
|
||||
|
||||
try: g.db.commit()
|
||||
except: g.db.rollback()
|
||||
g.db.commit()
|
||||
|
||||
return {"message": "Comment saved!"}
|
||||
|
||||
|
|
|
@ -89,12 +89,12 @@ def stats():
|
|||
"removed comments (by admins)": g.db.query(Comment.id).filter_by(is_banned=True).count(),
|
||||
"deleted comments (by author)": g.db.query(Comment.id).filter(Comment.deleted_utc > 0).count(),
|
||||
"comments last_24h": g.db.query(Comment.id).filter(Comment.created_utc > day, Comment.author_id.notin_((AUTOJANNY_ID,NOTIFICATIONS_ID))).count(),
|
||||
"post votes": g.db.query(CommentVote.submission_id).count(),
|
||||
"post votes": g.db.query(Vote.submission_id).count(),
|
||||
"post voting users": g.db.query(Vote.user_id).distinct().count(),
|
||||
"comment votes": g.db.query(CommentVote.comment_id).count(),
|
||||
"comment voting users": g.db.query(CommentVote.user_id).distinct().count(),
|
||||
"total upvotes": g.db.query(CommentVote.submission_id).filter_by(vote_type=1).count() + g.db.query(CommentVote.comment_id).filter_by(vote_type=1).count(),
|
||||
"total downvotes": g.db.query(CommentVote.submission_id).filter_by(vote_type=-1).count() + g.db.query(CommentVote.comment_id).filter_by(vote_type=-1).count(),
|
||||
"total upvotes": g.db.query(Vote.submission_id).filter_by(vote_type=1).count() + g.db.query(CommentVote.comment_id).filter_by(vote_type=1).count(),
|
||||
"total downvotes": g.db.query(Vote.submission_id).filter_by(vote_type=-1).count() + g.db.query(CommentVote.comment_id).filter_by(vote_type=-1).count(),
|
||||
"total awards": g.db.query(AwardRelationship.id).count(),
|
||||
"awards given": g.db.query(AwardRelationship.id).filter(or_(AwardRelationship.submission_id != None, AwardRelationship.comment_id != None)).count(),
|
||||
"users who posted or commented in the past 7 days": len(active_users)
|
||||
|
|
|
@ -98,15 +98,13 @@ def api_vote_post(post_id, new, v):
|
|||
)
|
||||
g.db.add(vote)
|
||||
|
||||
try:
|
||||
g.db.flush()
|
||||
post.upvotes = g.db.query(CommentVote.submission_id).filter_by(submission_id=post.id, vote_type=1).count()
|
||||
post.downvotes = g.db.query(CommentVote.submission_id).filter_by(submission_id=post.id, vote_type=-1).count()
|
||||
post.realupvotes = g.db.query(CommentVote.submission_id).filter_by(submission_id=post.id, real=True).count()
|
||||
if post.author.progressivestack: post.realupvotes *= 2
|
||||
g.db.add(post)
|
||||
g.db.commit()
|
||||
except: g.db.rollback()
|
||||
g.db.flush()
|
||||
post.upvotes = g.db.query(Vote.submission_id).filter_by(submission_id=post.id, vote_type=1).count()
|
||||
post.downvotes = g.db.query(Vote.submission_id).filter_by(submission_id=post.id, vote_type=-1).count()
|
||||
post.realupvotes = g.db.query(Vote.submission_id).filter_by(submission_id=post.id, real=True).count()
|
||||
if post.author.progressivestack: post.realupvotes *= 2
|
||||
g.db.add(post)
|
||||
g.db.commit()
|
||||
return "", 204
|
||||
|
||||
@app.post("/vote/comment/<comment_id>/<new>")
|
||||
|
@ -162,15 +160,13 @@ def api_vote_comment(comment_id, new, v):
|
|||
|
||||
g.db.add(vote)
|
||||
|
||||
try:
|
||||
g.db.flush()
|
||||
comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
|
||||
comment.downvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=-1).count()
|
||||
comment.realupvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, real=True).count()
|
||||
if comment.author.progressivestack: comment.realupvotes *= 2
|
||||
g.db.add(comment)
|
||||
g.db.commit()
|
||||
except: g.db.rollback()
|
||||
g.db.flush()
|
||||
comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
|
||||
comment.downvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=-1).count()
|
||||
comment.realupvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, real=True).count()
|
||||
if comment.author.progressivestack: comment.realupvotes *= 2
|
||||
g.db.add(comment)
|
||||
g.db.commit()
|
||||
return "", 204
|
||||
|
||||
|
||||
|
@ -199,12 +195,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)
|
||||
|
||||
try:
|
||||
g.db.flush()
|
||||
comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
|
||||
g.db.add(comment)
|
||||
g.db.commit()
|
||||
except: g.db.rollback()
|
||||
g.db.flush()
|
||||
comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
|
||||
g.db.add(comment)
|
||||
g.db.commit()
|
||||
return "", 204
|
||||
|
||||
|
||||
|
@ -263,10 +257,8 @@ def api_vote_choice(comment_id, v):
|
|||
g.db.add(vote.comment)
|
||||
g.db.delete(vote)
|
||||
|
||||
try:
|
||||
g.db.flush()
|
||||
comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
|
||||
g.db.add(comment)
|
||||
g.db.commit()
|
||||
except: g.db.rollback()
|
||||
g.db.flush()
|
||||
comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
|
||||
g.db.add(comment)
|
||||
g.db.commit()
|
||||
return "", 204
|
Loading…
Add table
Add a link
Reference in a new issue