From a23bdfc1f64553029838fa8cdaf937e349209972 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 14 Aug 2021 23:43:26 +0200 Subject: [PATCH] fdfd --- files/routes/admin.py | 34 ++++++++++++++-------------------- files/routes/front.py | 37 ++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 37 deletions(-) diff --git a/files/routes/admin.py b/files/routes/admin.py index 767d7fed4..d7e9bb5fd 100644 --- a/files/routes/admin.py +++ b/files/routes/admin.py @@ -43,21 +43,16 @@ def flagged_posts(v): page = max(1, int(request.args.get("page", 1))) - posts = g.db.query(Submission).filter_by( - is_approved=0, - is_banned=False - ).join(Submission.flags - ).options(contains_eager(Submission.flags) - ).order_by(Submission.id.desc()).offset(25 * (page - 1)).limit(26) + posts = g.db.query(Submission).filter_by(is_approved=0, is_banned=False).order_by(Submission.id.desc()) + posts = [p for p in posts if p.active_flags > 0] - listing = [p.id for p in posts] - next_exists = (len(listing) == 26) - listing = listing[:25] - - listing = get_posts(listing, v=v) + firstrange = 25 * (page - 1) + secondrange = firstrange+26 + posts = posts[firstrange:secondrange] + next_exists = (len(posts) == 26) return render_template("admin/flagged_posts.html", - next_exists=next_exists, listing=listing, page=page, v=v) + next_exists=next_exists, listing=posts[:25], page=page, v=v) @app.get("/admin/image_posts") @@ -80,20 +75,19 @@ def image_posts_listing(v): @app.get("/admin/flagged/comments") @admin_level_required(3) def flagged_comments(v): - page = max(1, int(request.args.get("page", 1))) - posts = g.db.query(Comment).filter_by(is_approved=0, is_banned=False).join(Comment.flags).options(contains_eager(Comment.flags)).order_by(Comment.id.desc()).offset(25 * (page - 1)).limit(26).all() + posts = g.db.query(Comment).filter_by(is_approved=0, is_banned=False).order_by(Comment.id.desc()) + posts = [p for p in posts if p.active_flags > 0] - listing = [p.id for p in posts] - next_exists = (len(listing) == 26) - listing = listing[:25] - - listing = get_comments(listing, v=v) + firstrange = 25 * (page - 1) + secondrange = firstrange+26 + posts = posts[firstrange:secondrange] + next_exists = (len(posts) == 26) return render_template("admin/flagged_comments.html", next_exists=next_exists, - listing=listing, + listing=posts, page=page, v=v, standalone=True) diff --git a/files/routes/front.py b/files/routes/front.py index 75d69e477..b2263f35b 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -73,9 +73,27 @@ def notifications(v): is_notification_page=True) @cache.memoize() -def frontlist(v=None, sort="hot", page=1,t="all", ids_only=True, filter_words='', **kwargs): +def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', **kwargs): + + posts = g.db.query(Submission).options(lazyload('*')) + + if t != 'all': + cutoff = 0 + now = int(time.time()) + if t == 'hour': + cutoff = now - 3600 + elif t == 'day': + cutoff = now - 86400 + elif t == 'week': + cutoff = now - 604800 + elif t == 'month': + cutoff = now - 2592000 + elif t == 'year': + cutoff = now - 31536000 + posts = posts.filter(Submission.created_utc >= cutoff) + + posts = posts.filter_by(is_banned=False,stickied=False,private=False).filter(Submission.deleted_utc == 0) - posts = g.db.query(Submission).options(lazyload('*')).filter_by(is_banned=False,stickied=False,private=False).filter(Submission.deleted_utc == 0) if v and v.admin_level == 0: blocking = g.db.query( UserBlock.target_id).filter_by( @@ -96,21 +114,6 @@ def frontlist(v=None, sort="hot", page=1,t="all", ids_only=True, filter_words='' for word in filter_words: posts=posts.filter(not_(SubmissionAux.title.ilike(f'%{word}%'))) - if t != 'all': - cutoff = 0 - now = int(time.time()) - if t == 'hour': - cutoff = now - 3600 - elif t == 'day': - cutoff = now - 86400 - elif t == 'week': - cutoff = now - 604800 - elif t == 'month': - cutoff = now - 2592000 - elif t == 'year': - cutoff = now - 31536000 - posts = posts.filter(Submission.created_utc >= cutoff) - gt = kwargs.get("gt") lt = kwargs.get("lt")