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
@lazy
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
@lazy
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

View File

@ -210,8 +210,7 @@ def get_comments(cids, v=None, load_parent=False):
).options(lazyload('*')).filter(Comment.id.in_(cids))
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.filter(Comment.author_id.notin_(shadowbanned))
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
comments = comments.join(
votes,
@ -236,8 +235,7 @@ def get_comments(cids, v=None, load_parent=False):
output.append(comment)
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('*')).filter(Comment.id.in_(cids), Comment.author_id.notin_(shadowbanned)).all()
output = g.db.query(Comment).options(lazyload('*')).join(User, User.id == Comment.author_id).filter(User.shadowbanned == None, Comment.id.in_(cids)).all()
if load_parent:
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()
@app.get("/truescore")
@admin_level_required(6)
def truescore(v):
@ -547,9 +546,7 @@ def admin_removed(v):
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('*')).filter(or_(Submission.is_banned==True, Submission.author_id.in_(shadowbanned))).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26).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=[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('*'))
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.filter(Comment.author_id.notin_(shadowbanned))
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
comments=comments.filter(
Comment.parent_submission == post.id,
@ -194,7 +193,7 @@ def api_comment(v):
if ban.reason: reason += f" {ban.reason}"
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.parent_comment_id == parent_comment_id,
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 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.filter(Submission.author_id.notin_(shadowbanned))
posts = posts.join(User, User.id == Submission.author_id).filter(User.shadowbanned == None)
if sort == "hot":
ti = int(time.time()) + 3600

View File

@ -133,8 +133,7 @@ def post_id(pid, anything=None, v=None):
).options(lazyload('*'))
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.filter(Comment.author_id.notin_(shadowbanned))
comments = comments.join(User, User.id == Comment.author_id).filter(User.shadowbanned == None)
comments=comments.filter(
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]
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('*')).filter(Comment.parent_submission == post.id, Comment.author_id != AUTOPOLLER_ACCOUNT, Comment.author_id.notin_(shadowbanned))
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)
if sort == "new":
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)
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)

View File

@ -12,7 +12,7 @@ def api_flag_post(pid, v):
post = get_post(pid)
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
@ -44,7 +44,7 @@ def api_flag_comment(cid, v):
comment = get_comment(cid)
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()
if existing: return "", 409

View File

@ -224,7 +224,7 @@ def settings_profile_post(v):
for x in notify_users:
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)
v.friends = friends[:500]
@ -527,7 +527,7 @@ def settings_security_post(v):
if new_email == v.email:
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()
if existing:
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!")
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!")
cache.delete_memoized(frontlist)

View File

@ -232,7 +232,7 @@ def message2(v, username):
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.body == message,
).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()
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!")
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()
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!")
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()
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!")
g.db.commit()

View File

@ -68,7 +68,7 @@ def api_vote_post(post_id, new, v):
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
@ -141,7 +141,7 @@ def api_vote_comment(comment_id, new, v):
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
@ -209,7 +209,7 @@ def api_vote_poll(comment_id, v):
comment_id = int(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