From e613f7864f218ea7f97c7c72e168fe695df7a2f8 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Tue, 28 Sep 2021 21:39:51 +0200 Subject: [PATCH] fgg4 --- files/classes/user.py | 32 ------------------------- files/helpers/get.py | 6 +++-- files/routes/awards.py | 2 +- files/routes/comments.py | 3 ++- files/routes/front.py | 8 +++---- files/routes/posts.py | 2 +- files/templates/settings2.html | 2 +- files/templates/submission_listing.html | 4 ++-- 8 files changed, 15 insertions(+), 44 deletions(-) diff --git a/files/classes/user.py b/files/classes/user.py index 98d1c3a79..f43a2fff4 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -422,38 +422,6 @@ class User(Base): return output - @lazy - def alts_threaded(self, db): - - subq = db.query(Alt).filter( - or_( - Alt.user1 == self.id, - Alt.user2 == self.id - ) - ).subquery() - - data = db.query( - User, - aliased(Alt, alias=subq) - ).join( - subq, - or_( - subq.c.user1 == User.id, - subq.c.user2 == User.id - ) - ).filter( - User.id != self.id - ).order_by(User.username.asc()).all() - - data = [x for x in data] - output = [] - for x in data: - user = x[0] - user._is_manual = x[1].is_manual - output.append(user) - - return output - def has_follower(self, user): return g.db.query(Follow).options(lazyload('*')).filter_by(target_id=self.id, user_id=user.id).first() diff --git a/files/helpers/get.py b/files/helpers/get.py index ae34f900f..2fce1abf9 100644 --- a/files/helpers/get.py +++ b/files/helpers/get.py @@ -213,7 +213,8 @@ def get_comments(cids, v=None, load_parent=False): ).filter(Comment.id.in_(cids)) if not (v and v.shadowbanned) and not (v and v.admin_level == 6): - comments = comments.join(Comment.author).filter(User.shadowbanned == False) + shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned == True).all()] + comments = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id.notin_(shadowbanned)) comments = comments.join( votes, @@ -238,7 +239,8 @@ def get_comments(cids, v=None, load_parent=False): output.append(comment) else: - output = g.db.query(Comment).join(Comment.author).options(lazyload('*')).filter(Comment.id.in_(cids), User.shadowbanned == False).all() + shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned == True).all()] + output = g.db.query(Comment).options(lazyload('*')).filter(Comment.id.in_(cids), Comment.author_id.notin_(shadowbanned)).all() if load_parent: parents = [x.parent_comment_id for x in output if x.parent_comment_id] diff --git a/files/routes/awards.py b/files/routes/awards.py index 51b6f4fe2..56b86b031 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -244,7 +244,7 @@ def award_post(pid, v): g.db.add(post.author) g.db.commit() - if len(request.referrer) > 1: return redirect(request.referrer) + if request.referrer and len(request.referrer) > 1: return redirect(request.referrer) else: return redirect("/") diff --git a/files/routes/comments.py b/files/routes/comments.py index 9887b61b2..69c53d091 100644 --- a/files/routes/comments.py +++ b/files/routes/comments.py @@ -85,7 +85,8 @@ def post_pid_comment_cid(cid, pid=None, anything=None, v=None): ) if not (v and v.shadowbanned) and not (v and v.admin_level == 6): - comments = comments.join(Comment.author).filter(User.shadowbanned == False) + shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned == True).all()] + comments = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id.notin_(shadowbanned)) if v.admin_level >=4: comments=comments.options(joinedload(Comment.oauth_app)) diff --git a/files/routes/front.py b/files/routes/front.py index 53f5ef934..818674cbb 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -197,7 +197,8 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' lt = kwargs.get("lt") if not (v and v.shadowbanned): - posts = posts.join(Submission.author).filter(User.shadowbanned == False) + shadowbanned = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.shadowbanned == True).all()] + posts = g.db.query(Submission).options(lazyload('*')).filter(Submission.author_id.notin_(shadowbanned)) if sort == "hot": ti = int(time.time()) + 3600 @@ -273,7 +274,8 @@ def changeloglist(v=None, sort="new", page=1 ,t="all", **kwargs): Submission.author_id.notin_(blocked) ) - posts=posts.filter(Submission.title.ilike(f'_changelog%', User.admin_level == 6)) + admins = [x[0] for x in g.db.query(User.id).options(lazyload('*')).filter(User.admin_level == 6).all()] + posts = posts.filter(Submission.title.ilike('_changelog%'), Submission.author_id.in_(admins)) if t != 'all': cutoff = 0 @@ -348,8 +350,6 @@ def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all", **kwargs): if not v or not v.admin_level >= 3: comments = comments.filter_by(is_banned=False).filter(Comment.deleted_utc == 0) - comments = comments.join(posts, Comment.parent_submission == posts.c.id) - now = int(time.time()) if t == 'hour': cutoff = now - 3600 diff --git a/files/routes/posts.py b/files/routes/posts.py index aa6c57131..5d373e7fd 100644 --- a/files/routes/posts.py +++ b/files/routes/posts.py @@ -114,7 +114,7 @@ def post_id(pid, anything=None, v=None): 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 == True).all()] - comments = g.db.query(Comment).filter(Comment.author_id.notin_(shadowbanned)) + comments = g.db.query(Comment).options(lazyload('*')).filter(Comment.author_id.notin_(shadowbanned)) comments = g.db.query( Comment, diff --git a/files/templates/settings2.html b/files/templates/settings2.html index 4faada059..2bca15e56 100644 --- a/files/templates/settings2.html +++ b/files/templates/settings2.html @@ -138,7 +138,7 @@ {% endif %} {% endblock %} -
+
{% block content %} {% endblock %} diff --git a/files/templates/submission_listing.html b/files/templates/submission_listing.html index 0a7105b4a..e27c47808 100644 --- a/files/templates/submission_listing.html +++ b/files/templates/submission_listing.html @@ -245,7 +245,7 @@
-