🏦 Database Change: convert created utc to datetimez for votes (#670)

This commit is contained in:
Viet Than 2023-08-02 22:16:29 -05:00 committed by GitHub
parent 53c78c4536
commit 15f387f109
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 7 deletions

View file

@ -1,11 +1,11 @@
from sqlalchemy import *
from sqlalchemy.orm import relationship
from files.classes.base import CreatedBase, CreatedDateTimeBase
from files.classes.base import CreatedDateTimeBase
from files.helpers.lazy import lazy
class Vote(CreatedBase):
class Vote(CreatedDateTimeBase):
__tablename__ = "votes"
submission_id = Column(Integer, ForeignKey("submissions.id"), primary_key=True)

View file

@ -55,7 +55,7 @@ def support(v):
def participation_stats(v):
day = int(time.time()) - 86400
week = int(time.time()) - 604800
week = int(time.time()) - 604800 # TODO themotte#601 use created_datetimez once all is converted
posters = g.db.query(Submission.author_id).distinct(Submission.author_id).filter(Submission.created_utc > week).all()
commenters = g.db.query(Comment.author_id).distinct(Comment.author_id).filter(Comment.created_utc > week).all()
voters = g.db.query(Vote.user_id).distinct(Vote.user_id).filter(Vote.created_utc > week).all()

View file

@ -29,18 +29,18 @@ def admin_vote_info_get(v):
thing_id = g.db.query(Submission.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Submission.id).first()[0]
else: thing_id = thing.id
ups = g.db.query(Vote).filter_by(submission_id=thing_id, vote_type=1).order_by(Vote.created_utc).all()
ups = g.db.query(Vote).filter_by(submission_id=thing_id, vote_type=1).order_by(Vote.created_datetimez).all()
downs = g.db.query(Vote).filter_by(submission_id=thing_id, vote_type=-1).order_by(Vote.created_utc).all()
downs = g.db.query(Vote).filter_by(submission_id=thing_id, vote_type=-1).order_by(Vote.created_datetimez).all()
elif isinstance(thing, Comment):
if thing.author.shadowbanned and not (v and v.admin_level):
thing_id = g.db.query(Comment.id).filter_by(upvotes=thing.upvotes, downvotes=thing.downvotes).order_by(Comment.id).first()[0]
else: thing_id = thing.id
ups = g.db.query(CommentVote).filter_by(comment_id=thing_id, vote_type=1).order_by(CommentVote.created_utc).all()
ups = g.db.query(CommentVote).filter_by(comment_id=thing_id, vote_type=1).order_by(CommentVote.created_datetimez).all()
downs = g.db.query(CommentVote).filter_by(comment_id=thing_id, vote_type=-1 ).order_by(CommentVote.created_utc).all()
downs = g.db.query(CommentVote).filter_by(comment_id=thing_id, vote_type=-1 ).order_by(CommentVote.created_datetimez).all()
else: abort(400)