forked from rDrama/rDrama
Use database to filter hidevotedon directly.
We no longer need to build a list of potentially tens of thousands of submission_ids in Python from the database to then pass back to the database.master
parent
c9aee3ebb8
commit
4afa60dc81
|
@ -96,14 +96,14 @@ def front_all(v, sub=None, subdomain=None):
|
||||||
|
|
||||||
@cache.memoize(timeout=86400)
|
@cache.memoize(timeout=86400)
|
||||||
def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', gt=0, lt=0, sub=None, site=None, pins=True, holes=True):
|
def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='', gt=0, lt=0, sub=None, site=None, pins=True, holes=True):
|
||||||
|
|
||||||
posts = g.db.query(Submission)
|
posts = g.db.query(Submission)
|
||||||
|
|
||||||
if v and v.hidevotedon:
|
if v and v.hidevotedon:
|
||||||
voted = [x[0] for x in g.db.query(Vote.submission_id).filter_by(user_id=v.id).all()]
|
posts = posts.outerjoin(Vote,
|
||||||
posts = posts.filter(Submission.id.notin_(voted))
|
and_(Vote.submission_id == Submission.id, Vote.user_id == v.id)
|
||||||
|
).filter(Vote.submission_id == None)
|
||||||
|
|
||||||
if sub: posts = posts.filter_by(sub=sub.name)
|
if sub: posts = posts.filter(Submission.sub == sub.name)
|
||||||
elif v: posts = posts.filter(or_(Submission.sub == None, Submission.sub.notin_(v.all_blocks)))
|
elif v: posts = posts.filter(or_(Submission.sub == None, Submission.sub.notin_(v.all_blocks)))
|
||||||
|
|
||||||
if gt: posts = posts.filter(Submission.created_utc > gt)
|
if gt: posts = posts.filter(Submission.created_utc > gt)
|
||||||
|
@ -112,11 +112,15 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
|
||||||
if not gt and not lt:
|
if not gt and not lt:
|
||||||
posts = apply_time_filter(t, posts, Submission)
|
posts = apply_time_filter(t, posts, Submission)
|
||||||
|
|
||||||
posts = posts.filter_by(is_banned=False, private=False, deleted_utc = 0)
|
posts = posts.filter(
|
||||||
|
Submission.is_banned == False,
|
||||||
|
Submission.private == False,
|
||||||
|
Submission.deleted_utc == 0,
|
||||||
|
)
|
||||||
|
|
||||||
if pins and not gt and not lt:
|
if pins and not gt and not lt:
|
||||||
if sub: posts = posts.filter_by(hole_pinned=None)
|
if sub: posts = posts.filter(Submission.hole_pinned == None)
|
||||||
else: posts = posts.filter_by(stickied=None)
|
else: posts = posts.filter(Submission.stickied == None)
|
||||||
|
|
||||||
if not sub and not holes:
|
if not sub and not holes:
|
||||||
posts = posts.filter(or_(Submission.sub == None, Submission.sub == 'changelog'))
|
posts = posts.filter(or_(Submission.sub == None, Submission.sub == 'changelog'))
|
||||||
|
|
Loading…
Reference in New Issue