remotes/1693045480750635534/spooky-22
Aevann1 2021-11-06 02:33:32 +02:00
parent 3dcf1d6f7a
commit 0ed1212131
10 changed files with 24 additions and 33 deletions

View File

@ -343,12 +343,12 @@ class User(Base):
@property @property
@lazy @lazy
def notifications_count(self): def notifications_count(self):
return g.db.query(Notification.id, Comment.is_banned, Comment.deleted_utc).options(lazyload('*')).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.id).options(lazyload('*')).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.is_banned == False, Comment.deleted_utc == 0).count()
@property @property
@lazy @lazy
def post_notifications_count(self): def post_notifications_count(self):
return g.db.query(Notification.id, Comment.author_id).options(lazyload('*')).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.author_id == AUTOJANNY_ACCOUNT).count() return g.db.query(Notification.id).options(lazyload('*')).join(Comment).filter(Notification.user_id == self.id, Notification.read == False, Comment.author_id == AUTOJANNY_ACCOUNT).count()
@property @property

View File

@ -210,8 +210,7 @@ def get_comments(cids, v=None, load_parent=False):
).options(lazyload('*')).filter(Comment.id.in_(cids)) ).options(lazyload('*')).filter(Comment.id.in_(cids))
if not (v and v.shadowbanned) and not (v and v.admin_level == 6): if not (v and v.shadowbanned) and not (v and v.admin_level == 6):
shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned != None).all()] comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
comments = comments.filter(Comment.author_id.notin_(shadowbanned))
comments = comments.join( comments = comments.join(
votes, votes,
@ -236,8 +235,7 @@ def get_comments(cids, v=None, load_parent=False):
output.append(comment) output.append(comment)
else: else:
shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned != None).all()] output = g.db.query(Comment).options(lazyload('*')).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.id.in_(cids)).all()
output = g.db.query(Comment).options(lazyload('*')).filter(Comment.id.in_(cids), Comment.author_id.notin_(shadowbanned)).all()
if load_parent: if load_parent:
parents = [x.parent_comment_id for x in output if x.parent_comment_id] parents = [x.parent_comment_id for x in output if x.parent_comment_id]

View File

@ -20,7 +20,6 @@ from files.helpers.discord import add_role
SITE_NAME = environ.get("SITE_NAME", "").strip() SITE_NAME = environ.get("SITE_NAME", "").strip()
@app.get("/truescore") @app.get("/truescore")
@admin_level_required(6) @admin_level_required(6)
def truescore(v): def truescore(v):
@ -547,9 +546,7 @@ def admin_removed(v):
page = int(request.values.get("page", 1)) page = int(request.values.get("page", 1))
shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned != None).all()] ids = g.db.query(Submission.id).options(lazyload('*')).join(User, User.id == Submission.author_id).filter(or_(Submission.is_banned==True, User.shadowbanned != None)).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26).all()
ids = g.db.query(Submission.id).options(lazyload('*')).filter(or_(Submission.is_banned==True, Submission.author_id.in_(shadowbanned))).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26).all()
ids=[x[0] for x in ids] ids=[x[0] for x in ids]

View File

@ -91,8 +91,7 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None):
).options(lazyload('*')) ).options(lazyload('*'))
if not (v and v.shadowbanned) and not (v and v.admin_level == 6): if not (v and v.shadowbanned) and not (v and v.admin_level == 6):
shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned != None).all()] comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
comments = comments.filter(Comment.author_id.notin_(shadowbanned))
comments=comments.filter( comments=comments.filter(
Comment.parent_submission == post.id, Comment.parent_submission == post.id,
@ -194,7 +193,7 @@ def api_comment(v):
if ban.reason: reason += f" {ban.reason}" if ban.reason: reason += f" {ban.reason}"
return {"error": reason}, 401 return {"error": reason}, 401
existing = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id == v.id, existing = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == v.id,
Comment.deleted_utc == 0, Comment.deleted_utc == 0,
Comment.parent_comment_id == parent_comment_id, Comment.parent_comment_id == parent_comment_id,
Comment.parent_submission == parent_submission, Comment.parent_submission == parent_submission,

View File

@ -185,8 +185,7 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
if lt: posts = posts.filter(Submission.created_utc < lt) if lt: posts = posts.filter(Submission.created_utc < lt)
if not (v and v.shadowbanned): if not (v and v.shadowbanned):
shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned != None).all()] posts = posts.join(User, User.id == Submission.author_id).filter(User.shadowbanned == None)
posts = posts.filter(Submission.author_id.notin_(shadowbanned))
if sort == "hot": if sort == "hot":
ti = int(time.time()) + 3600 ti = int(time.time()) + 3600

View File

@ -133,8 +133,7 @@ def post_id(pid, anything=None, v=None):
).options(lazyload('*')) ).options(lazyload('*'))
if not (v and v.shadowbanned) and not (v and v.admin_level == 6): if not (v and v.shadowbanned) and not (v and v.admin_level == 6):
shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned != None).all()] comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
comments = comments.filter(Comment.author_id.notin_(shadowbanned))
comments=comments.filter( comments=comments.filter(
Comment.parent_submission == post.id, Comment.parent_submission == post.id,
@ -174,8 +173,7 @@ def post_id(pid, anything=None, v=None):
post.replies = [x for x in output if x.is_pinned] + [x for x in output if x.level == 1 and not x.is_pinned] post.replies = [x for x in output if x.is_pinned] + [x for x in output if x.level == 1 and not x.is_pinned]
else: else:
shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned != None).all()] comments = g.db.query(Comment).options(lazyload('*')).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.parent_submission == post.id, Comment.author_id != AUTOPOLLER_ACCOUNT)
comments = g.db.query(Comment).options(lazyload('*')).filter(Comment.parent_submission == post.id, Comment.author_id != AUTOPOLLER_ACCOUNT, Comment.author_id.notin_(shadowbanned))
if sort == "new": if sort == "new":
comments = comments.order_by(Comment.created_utc.desc()) comments = comments.order_by(Comment.created_utc.desc())
@ -338,7 +336,7 @@ def edit_post(pid, v):
if 'carp' in f'{body_html}{title}'.lower() and 995 not in notify_users: notify_users.add(995) if 'carp' in f'{body_html}{title}'.lower() and 995 not in notify_users: notify_users.add(995)
for x in notify_users: for x in notify_users:
existing = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first() existing = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first()
if not existing: send_notification(x, message) if not existing: send_notification(x, message)

View File

@ -12,7 +12,7 @@ def api_flag_post(pid, v):
post = get_post(pid) post = get_post(pid)
if v and not v.shadowbanned: if v and not v.shadowbanned:
existing = g.db.query(Flag).options(lazyload('*')).filter_by(user_id=v.id, post_id=post.id).first() existing = g.db.query(Flag.id).options(lazyload('*')).filter_by(user_id=v.id, post_id=post.id).first()
if existing: return "", 409 if existing: return "", 409
@ -44,7 +44,7 @@ def api_flag_comment(cid, v):
comment = get_comment(cid) comment = get_comment(cid)
if v and not v.shadowbanned: if v and not v.shadowbanned:
existing = g.db.query(CommentFlag).options(lazyload('*')).filter_by( existing = g.db.query(CommentFlag.id).options(lazyload('*')).filter_by(
user_id=v.id, comment_id=comment.id).first() user_id=v.id, comment_id=comment.id).first()
if existing: return "", 409 if existing: return "", 409

View File

@ -224,7 +224,7 @@ def settings_profile_post(v):
for x in notify_users: for x in notify_users:
message = f"@{v.username} has added you to their top friends!" message = f"@{v.username} has added you to their top friends!"
existing = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first() existing = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == NOTIFICATIONS_ACCOUNT, Comment.body == message, Comment.notifiedto == x).first()
if not existing: send_notification(x, message) if not existing: send_notification(x, message)
v.friends = friends[:500] v.friends = friends[:500]
@ -527,7 +527,7 @@ def settings_security_post(v):
if new_email == v.email: if new_email == v.email:
return redirect("/settings/security?error=That email is already yours!") return redirect("/settings/security?error=That email is already yours!")
existing = g.db.query(User).options(lazyload('*')).filter(User.id != v.id, existing = g.db.query(User.id).options(lazyload('*')).filter(User.id != v.id,
func.lower(User.email) == new_email.lower()).first() func.lower(User.email) == new_email.lower()).first()
if existing: if existing:
return redirect("/settings/security?error=" + return redirect("/settings/security?error=" +
@ -770,7 +770,7 @@ def settings_block_user(v):
existing = g.db.query(Notification).options(lazyload('*')).filter_by(blocksender=v.id, user_id=user.id).first() existing = g.db.query(Notification.id).options(lazyload('*')).filter_by(blocksender=v.id, user_id=user.id).first()
if not existing: send_block_notif(v.id, user.id, f"@{v.username} has blocked you!") if not existing: send_block_notif(v.id, user.id, f"@{v.username} has blocked you!")
cache.delete_memoized(frontlist) cache.delete_memoized(frontlist)
@ -797,7 +797,7 @@ def settings_unblock_user(v):
existing = g.db.query(Notification).options(lazyload('*')).filter_by(unblocksender=v.id, user_id=user.id).first() existing = g.db.query(Notification.id).options(lazyload('*')).filter_by(unblocksender=v.id, user_id=user.id).first()
if not existing: send_unblock_notif(v.id, user.id, f"@{v.username} has unblocked you!") if not existing: send_unblock_notif(v.id, user.id, f"@{v.username} has unblocked you!")
cache.delete_memoized(frontlist) cache.delete_memoized(frontlist)

View File

@ -232,7 +232,7 @@ def message2(v, username):
message = request.values.get("message", "").strip()[:1000].strip() message = request.values.get("message", "").strip()[:1000].strip()
existing = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id == v.id, existing = g.db.query(Comment.id).options(lazyload('*')).filter(Comment.author_id == v.id,
Comment.sentto == user.id, Comment.sentto == user.id,
Comment.body == message, Comment.body == message,
).first() ).first()
@ -628,7 +628,7 @@ def follow_user(username, v):
target.stored_subscriber_count = g.db.query(Follow.id).options(lazyload('*')).filter_by(target_id=target.id).count() target.stored_subscriber_count = g.db.query(Follow.id).options(lazyload('*')).filter_by(target_id=target.id).count()
g.db.add(target) g.db.add(target)
existing = g.db.query(Notification).options(lazyload('*')).filter_by(followsender=v.id, user_id=target.id).first() existing = g.db.query(Notification.id).options(lazyload('*')).filter_by(followsender=v.id, user_id=target.id).first()
if not existing: send_follow_notif(v.id, target.id, f"@{v.username} has followed you!") if not existing: send_follow_notif(v.id, target.id, f"@{v.username} has followed you!")
g.db.commit() g.db.commit()
@ -654,7 +654,7 @@ def unfollow_user(username, v):
target.stored_subscriber_count = g.db.query(Follow.id).options(lazyload('*')).filter_by(target_id=target.id).count() target.stored_subscriber_count = g.db.query(Follow.id).options(lazyload('*')).filter_by(target_id=target.id).count()
g.db.add(target) g.db.add(target)
existing = g.db.query(Notification).options(lazyload('*')).filter_by(unfollowsender=v.id, user_id=target.id).first() existing = g.db.query(Notification.id).options(lazyload('*')).filter_by(unfollowsender=v.id, user_id=target.id).first()
if not existing: send_unfollow_notif(v.id, target.id, f"@{v.username} has unfollowed you!") if not existing: send_unfollow_notif(v.id, target.id, f"@{v.username} has unfollowed you!")
g.db.commit() g.db.commit()
@ -677,7 +677,7 @@ def remove_follow(username, v):
v.stored_subscriber_count = g.db.query(Follow.id).options(lazyload('*')).filter_by(target_id=v.id).count() v.stored_subscriber_count = g.db.query(Follow.id).options(lazyload('*')).filter_by(target_id=v.id).count()
g.db.add(v) g.db.add(v)
existing = g.db.query(Notification).options(lazyload('*')).filter_by(removefollowsender=v.id, user_id=target.id).first() existing = g.db.query(Notification.id).options(lazyload('*')).filter_by(removefollowsender=v.id, user_id=target.id).first()
if not existing: send_unfollow_notif(v.id, target.id, f"@{v.username} has removed your follow!") if not existing: send_unfollow_notif(v.id, target.id, f"@{v.username} has removed your follow!")
g.db.commit() g.db.commit()

View File

@ -68,7 +68,7 @@ def api_vote_post(post_id, new, v):
post = get_post(post_id) post = get_post(post_id)
existing = g.db.query(Vote).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post.id).first() existing = g.db.query(Vote.id).options(lazyload('*')).filter_by(user_id=v.id, submission_id=post.id).first()
if existing and existing.vote_type == new: return "", 204 if existing and existing.vote_type == new: return "", 204
@ -141,7 +141,7 @@ def api_vote_comment(comment_id, new, v):
comment = get_comment(comment_id) comment = get_comment(comment_id)
existing = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id).first() existing = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id).first()
if existing and existing.vote_type == new: return "", 204 if existing and existing.vote_type == new: return "", 204
@ -209,7 +209,7 @@ def api_vote_poll(comment_id, v):
comment_id = int(comment_id) comment_id = int(comment_id)
comment = get_comment(comment_id) comment = get_comment(comment_id)
existing = g.db.query(CommentVote).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id).first() existing = g.db.query(CommentVote.id).options(lazyload('*')).filter_by(user_id=v.id, comment_id=comment.id).first()
if existing and existing.vote_type == new: return "", 204 if existing and existing.vote_type == new: return "", 204