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"
|
__tablename__ = "votes"
|
||||||
|
|
||||||
id = Column(Integer, primary_key=True)
|
submission_id = Column(Integer, ForeignKey("submissions.id"), primary_key=True)
|
||||||
user_id = Column(Integer, ForeignKey("users.id"))
|
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
|
||||||
vote_type = Column(Integer)
|
vote_type = Column(Integer)
|
||||||
submission_id = Column(Integer, ForeignKey("submissions.id"))
|
|
||||||
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
|
||||||
real = Column(Boolean, default=True)
|
real = Column(Boolean, default=True)
|
||||||
created_utc = Column(Integer)
|
created_utc = Column(Integer)
|
||||||
|
|
|
@ -1008,8 +1008,7 @@ def save_comment(cid, v):
|
||||||
new_save=CommentSaveRelationship(user_id=v.id, comment_id=comment.id)
|
new_save=CommentSaveRelationship(user_id=v.id, comment_id=comment.id)
|
||||||
g.db.add(new_save)
|
g.db.add(new_save)
|
||||||
|
|
||||||
try: g.db.commit()
|
g.db.commit()
|
||||||
except: g.db.rollback()
|
|
||||||
|
|
||||||
return {"message": "Comment saved!"}
|
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(),
|
"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(),
|
"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(),
|
"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(),
|
"post voting users": g.db.query(Vote.user_id).distinct().count(),
|
||||||
"comment votes": g.db.query(CommentVote.comment_id).count(),
|
"comment votes": g.db.query(CommentVote.comment_id).count(),
|
||||||
"comment voting users": g.db.query(CommentVote.user_id).distinct().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 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(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(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(),
|
"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(),
|
"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)
|
"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)
|
g.db.add(vote)
|
||||||
|
|
||||||
try:
|
g.db.flush()
|
||||||
g.db.flush()
|
post.upvotes = g.db.query(Vote.submission_id).filter_by(submission_id=post.id, vote_type=1).count()
|
||||||
post.upvotes = g.db.query(CommentVote.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.downvotes = g.db.query(CommentVote.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()
|
||||||
post.realupvotes = g.db.query(CommentVote.submission_id).filter_by(submission_id=post.id, real=True).count()
|
if post.author.progressivestack: post.realupvotes *= 2
|
||||||
if post.author.progressivestack: post.realupvotes *= 2
|
g.db.add(post)
|
||||||
g.db.add(post)
|
g.db.commit()
|
||||||
g.db.commit()
|
|
||||||
except: g.db.rollback()
|
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
@app.post("/vote/comment/<comment_id>/<new>")
|
@app.post("/vote/comment/<comment_id>/<new>")
|
||||||
|
@ -162,15 +160,13 @@ def api_vote_comment(comment_id, new, v):
|
||||||
|
|
||||||
g.db.add(vote)
|
g.db.add(vote)
|
||||||
|
|
||||||
try:
|
g.db.flush()
|
||||||
g.db.flush()
|
comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
|
||||||
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.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()
|
||||||
comment.realupvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, real=True).count()
|
if comment.author.progressivestack: comment.realupvotes *= 2
|
||||||
if comment.author.progressivestack: comment.realupvotes *= 2
|
g.db.add(comment)
|
||||||
g.db.add(comment)
|
g.db.commit()
|
||||||
g.db.commit()
|
|
||||||
except: g.db.rollback()
|
|
||||||
return "", 204
|
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)
|
vote = CommentVote(user_id=v.id, vote_type=new, comment_id=comment.id)
|
||||||
g.db.add(vote)
|
g.db.add(vote)
|
||||||
|
|
||||||
try:
|
g.db.flush()
|
||||||
g.db.flush()
|
comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
|
||||||
comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
|
g.db.add(comment)
|
||||||
g.db.add(comment)
|
g.db.commit()
|
||||||
g.db.commit()
|
|
||||||
except: g.db.rollback()
|
|
||||||
return "", 204
|
return "", 204
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,10 +257,8 @@ def api_vote_choice(comment_id, v):
|
||||||
g.db.add(vote.comment)
|
g.db.add(vote.comment)
|
||||||
g.db.delete(vote)
|
g.db.delete(vote)
|
||||||
|
|
||||||
try:
|
g.db.flush()
|
||||||
g.db.flush()
|
comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
|
||||||
comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=comment.id, vote_type=1).count()
|
g.db.add(comment)
|
||||||
g.db.add(comment)
|
g.db.commit()
|
||||||
g.db.commit()
|
|
||||||
except: g.db.rollback()
|
|
||||||
return "", 204
|
return "", 204
|
Loading…
Add table
Add a link
Reference in a new issue