Refactor /comments to use single query.

master
Snakes 2022-10-13 01:52:54 -04:00
parent ed27225d10
commit 2edeb48751
Signed by: Snakes
GPG Key ID: E745A82778055C7E
1 changed files with 11 additions and 11 deletions

View File

@ -213,22 +213,22 @@ def all_comments(v):
return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists)
@cache.memoize(timeout=86400)
def comment_idlist(page=1, v=None, nsfw=False, sort="new", t="all", gt=0, lt=0, site=None):
comments = g.db.query(Comment.id).filter(Comment.parent_submission != None, Comment.author_id.notin_(v.userblocks))
def comment_idlist(v=None, page=1, sort="new", t="all", gt=0, lt=0, site=None):
comments = g.db.query(Comment.id) \
.join(Comment.post) \
.filter(Comment.parent_submission != None)
if v.admin_level < PERMS['POST_COMMENT_MODERATION']:
private = [x[0] for x in g.db.query(Submission.id).filter(Submission.private == True).all()]
comments = comments.filter(Comment.is_banned==False, Comment.deleted_utc == 0, Comment.parent_submission.notin_(private))
comments = comments.filter(
Comment.is_banned == False,
Comment.deleted_utc == 0,
Submission.private == False,
Comment.author_id.notin_(v.userblocks),
)
if not v.paid_dues:
club = [x[0] for x in g.db.query(Submission.id).filter(Submission.club == True).all()]
comments = comments.filter(Comment.parent_submission.notin_(club))
comments = comments.filter(Submission.club == False)
if gt: comments = comments.filter(Comment.created_utc > gt)
if lt: comments = comments.filter(Comment.created_utc < lt)