remotes/1693045480750635534/spooky-22
Aevann1 2022-02-16 03:16:01 +02:00
parent 850b97792c
commit 729e4a4c62
13 changed files with 47 additions and 53 deletions

View File

@ -66,10 +66,9 @@ class ClientAuth(Base):
__tablename__ = "client_auths"
id = Column(Integer, primary_key=True)
oauth_client = Column(Integer, ForeignKey("oauth_apps.id"))
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
oauth_client = Column(Integer, ForeignKey("oauth_apps.id"), primary_key=True)
access_token = Column(String)
user_id = Column(Integer, ForeignKey("users.id"))
user = relationship("User", viewonly=True)
application = relationship("OauthApp", viewonly=True)

View File

@ -73,7 +73,7 @@ class Comment(Base):
@property
@lazy
def flags(self):
return g.db.query(CommentFlag).filter_by(comment_id=self.id).order_by(CommentFlag.id)
return g.db.query(CommentFlag).filter_by(comment_id=self.id).order_by(CommentFlag.created_utc)
@lazy
def poll_voted(self, v):
@ -446,9 +446,8 @@ class Notification(Base):
__tablename__ = "notifications"
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"))
comment_id = Column(Integer, ForeignKey("comments.id"))
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
comment_id = Column(Integer, ForeignKey("comments.id"), primary_key=True)
read = Column(Boolean, default=False)
created_utc = Column(Integer)

View File

@ -9,9 +9,8 @@ class Flag(Base):
__tablename__ = "flags"
id = Column(Integer, primary_key=True)
post_id = Column(Integer, ForeignKey("submissions.id"))
user_id = Column(Integer, ForeignKey("users.id"))
post_id = Column(Integer, ForeignKey("submissions.id"), primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
reason = Column(String)
created_utc = Column(Integer)
@ -43,9 +42,8 @@ class CommentFlag(Base):
__tablename__ = "commentflags"
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"))
comment_id = Column(Integer, ForeignKey("comments.id"))
comment_id = Column(Integer, ForeignKey("comments.id"), primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
reason = Column(String)
created_utc = Column(Integer)

View File

@ -81,7 +81,7 @@ class Submission(Base):
@property
@lazy
def flags(self):
return g.db.query(Flag).filter_by(post_id=self.id).order_by(Flag.id)
return g.db.query(Flag).filter_by(post_id=self.id).order_by(Flag.created_utc)
@property
@lazy

View File

@ -1,7 +1,7 @@
from sqlalchemy import *
from sqlalchemy.orm import relationship
from files.__main__ import Base
import time
class Subscription(Base):
__tablename__ = "subscriptions"
@ -19,9 +19,8 @@ class Subscription(Base):
class Follow(Base):
__tablename__ = "follows"
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"))
target_id = Column(Integer, ForeignKey("users.id"))
target_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
created_utc = Column(Integer)
user = relationship("User", uselist=False, primaryjoin="User.id==Follow.user_id", viewonly=True)

View File

@ -294,7 +294,7 @@ class User(Base):
@property
@lazy
def follow_count(self):
return g.db.query(Follow.id).filter_by(user_id=self.id).count()
return g.db.query(Follow.target_id).filter_by(user_id=self.id).count()
@property
@lazy
@ -399,12 +399,12 @@ class User(Base):
@property
@lazy
def notifications_count(self):
return g.db.query(Notification.id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0).count()
return g.db.query(Notification.user_id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0).count()
@property
@lazy
def post_notifications_count(self):
return g.db.query(Notification.id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.author_id == AUTOJANNY_ID).count()
return g.db.query(Notification.user_id).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.author_id == AUTOJANNY_ID).count()
@property
@lazy

View File

@ -51,10 +51,9 @@ class CommentVote(Base):
__tablename__ = "commentvotes"
id = Column(Integer, primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"))
comment_id = Column(Integer, ForeignKey("comments.id"), primary_key=True)
user_id = Column(Integer, ForeignKey("users.id"), primary_key=True)
vote_type = Column(Integer)
comment_id = Column(Integer, ForeignKey("comments.id"))
app_id = Column(Integer, ForeignKey("oauth_apps.id"))
real = Column(Boolean, default=True)
created_utc = Column(Integer)

View File

@ -27,7 +27,7 @@ def send_repeatable_notification(uid, text, autojanny=False):
if existing_comment:
cid = existing_comment[0]
existing_notif = g.db.query(Notification.id).filter_by(user_id=uid, comment_id=cid).one_or_none()
existing_notif = g.db.query(Notification.user_id).filter_by(user_id=uid, comment_id=cid).one_or_none()
if existing_notif: cid = create_comment(text_html, autojanny)
else: cid = create_comment(text_html, autojanny)
@ -55,7 +55,7 @@ def notif_comment(text, autojanny=False):
def add_notif(cid, uid):
existing = g.db.query(Notification.id).filter_by(comment_id=cid, user_id=uid).one_or_none()
existing = g.db.query(Notification.user_id).filter_by(comment_id=cid, user_id=uid).one_or_none()
if not existing:
notif = Notification(comment_id=cid, user_id=uid)
g.db.add(notif)

View File

@ -23,7 +23,7 @@ def unread(v):
Comment.is_banned == False,
Comment.deleted_utc == 0,
Comment.author_id != AUTOJANNY_ID,
).order_by(Notification.id.desc()).all()
).order_by(Notification.created_utc.desc()).all()
for n in v.notifications.filter_by(read=False).all():
n.read = True
@ -50,7 +50,7 @@ def notifications(v):
next_exists = (len(comments) > 25)
comments = comments[:25]
elif posts:
notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ID).order_by(Notification.id.desc()).offset(25 * (page - 1)).limit(101).all()
notifications = v.notifications.join(Notification.comment).filter(Comment.author_id == AUTOJANNY_ID).order_by(Notification.created_utc.desc()).offset(25 * (page - 1)).limit(101).all()
listing = []
@ -72,7 +72,7 @@ def notifications(v):
Comment.is_banned == False,
Comment.deleted_utc == 0,
Comment.author_id != AUTOJANNY_ID,
).order_by(Notification.id.desc()).offset(50 * (page - 1)).limit(51).all()
).order_by(Notification.created_utc.desc()).offset(50 * (page - 1)).limit(51).all()
next_exists = (len(notifications) > 50)
notifications = notifications[:50]

View File

@ -16,7 +16,7 @@ def api_flag_post(pid, v):
reason = request.values.get("reason", "").strip()[:100]
if not reason.startswith('!'):
existing = g.db.query(Flag.id).filter_by(user_id=v.id, post_id=post.id).one_or_none()
existing = g.db.query(Flag.post_id).filter_by(user_id=v.id, post_id=post.id).one_or_none()
if existing: return "", 409
reason = filter_emojis_only(reason)
@ -43,7 +43,7 @@ def api_flag_comment(cid, v):
comment = get_comment(cid)
if not v.shadowbanned:
existing = g.db.query(CommentFlag.id).filter_by( user_id=v.id, comment_id=comment.id).one_or_none()
existing = g.db.query(CommentFlag.comment_id).filter_by( user_id=v.id, comment_id=comment.id).one_or_none()
if existing: return "", 409
reason = request.values.get("reason", "").strip()[:100]

View File

@ -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(Vote.id).count(),
"post votes": g.db.query(CommentVote.submission_id).count(),
"post voting users": g.db.query(Vote.user_id).distinct().count(),
"comment votes": g.db.query(CommentVote.id).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(Vote.id).filter_by(vote_type=1).count() + g.db.query(CommentVote.id).filter_by(vote_type=1).count(),
"total downvotes": g.db.query(Vote.id).filter_by(vote_type=-1).count() + g.db.query(CommentVote.id).filter_by(vote_type=-1).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 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)

View File

@ -658,14 +658,14 @@ def redditor_moment_redirect(username, v):
@auth_required
def followers(username, v):
u = get_user(username, v=v)
users = g.db.query(User).join(Follow, Follow.target_id == u.id).filter(Follow.user_id == User.id).order_by(Follow.id).all()
users = g.db.query(User).join(Follow, Follow.target_id == u.id).filter(Follow.user_id == User.id).order_by(Follow.created_utc).all()
return render_template("followers.html", v=v, u=u, users=users)
@app.get("/@<username>/following")
@auth_required
def following(username, v):
u = get_user(username, v=v)
users = g.db.query(User).join(Follow, Follow.user_id == u.id).filter(Follow.target_id == User.id).order_by(Follow.id).all()
users = g.db.query(User).join(Follow, Follow.user_id == u.id).filter(Follow.target_id == User.id).order_by(Follow.created_utc).all()
return render_template("following.html", v=v, u=u, users=users)
@app.get("/views")
@ -907,7 +907,7 @@ def follow_user(username, v):
g.db.add(new_follow)
g.db.flush()
target.stored_subscriber_count = g.db.query(Follow.id).filter_by(target_id=target.id).count()
target.stored_subscriber_count = g.db.query(Follow.target_id).filter_by(target_id=target.id).count()
g.db.add(target)
send_notification(target.id, f"@{v.username} has followed you!")
@ -931,7 +931,7 @@ def unfollow_user(username, v):
g.db.delete(follow)
g.db.flush()
target.stored_subscriber_count = g.db.query(Follow.id).filter_by(target_id=target.id).count()
target.stored_subscriber_count = g.db.query(Follow.target_id).filter_by(target_id=target.id).count()
g.db.add(target)
send_notification(target.id, f"@{v.username} has unfollowed you!")
@ -953,7 +953,7 @@ def remove_follow(username, v):
g.db.delete(follow)
g.db.flush()
v.stored_subscriber_count = g.db.query(Follow.id).filter_by(target_id=v.id).count()
v.stored_subscriber_count = g.db.query(Follow.target_id).filter_by(target_id=v.id).count()
g.db.add(v)
send_repeatable_notification(target.id, f"@{v.username} has removed your follow!")

View File

@ -28,18 +28,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.id).all()
ups = 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.id).all()
downs = g.db.query(Vote).filter_by(submission_id=thing_id, vote_type=-1).order_by(Vote.created_utc).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.id).all()
ups = 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.id).all()
downs = g.db.query(CommentVote).filter_by(comment_id=thing_id, vote_type=-1 ).order_by(CommentVote.created_utc).all()
else: abort(400)
@ -100,9 +100,9 @@ def api_vote_post(post_id, new, v):
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, real=True).count()
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()
@ -164,9 +164,9 @@ def api_vote_comment(comment_id, new, v):
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, real=True).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.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()
@ -201,7 +201,7 @@ def api_vote_poll(comment_id, v):
try:
g.db.flush()
comment.upvotes = g.db.query(CommentVote.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.commit()
except: g.db.rollback()
@ -259,13 +259,13 @@ def api_vote_choice(comment_id, v):
else: parent = comment.post
for vote in parent.total_choice_voted(v):
vote.comment.upvotes = g.db.query(CommentVote.id).filter_by(comment_id=vote.comment.id, vote_type=1).count() - 1
vote.comment.upvotes = g.db.query(CommentVote.comment_id).filter_by(comment_id=vote.comment.id, vote_type=1).count() - 1
g.db.add(vote.comment)
g.db.delete(vote)
try:
g.db.flush()
comment.upvotes = g.db.query(CommentVote.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.commit()
except: g.db.rollback()