diff --git a/files/routes/front.py b/files/routes/front.py
index d3859e130..cc3ee874b 100644
--- a/files/routes/front.py
+++ b/files/routes/front.py
@@ -108,12 +108,13 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words='
word = word.replace('\\', '').replace('_', '\_').replace('%', '\%').strip()
posts=posts.filter(not_(Submission.title.ilike(f'%{word}%')))
+ next_exists = posts.count()
+
posts = sort_objects(sort, posts, Submission)
if v: size = v.frontsize or 0
else: size = PAGE_SIZE
- next_exists = posts.count()
posts = posts.options(load_only(Submission.id)).offset(size * (page - 1))
if SITE_NAME == 'WPD' and sort == "hot" and sub == None:
@@ -180,8 +181,9 @@ def random_user(v:User):
@cache.memoize()
def comment_idlist(v=None, page=1, sort="new", t="day", gt=0, lt=0):
- comments = g.db.query(Comment.id) \
+ comments = g.db.query(Comment) \
.outerjoin(Comment.post) \
+ .options(load_only(Comment.id)) \
.filter(
or_(Comment.parent_submission != None, Comment.wall_user_id != None),
)
@@ -200,10 +202,11 @@ def comment_idlist(v=None, page=1, sort="new", t="day", gt=0, lt=0):
if not gt and not lt:
comments = apply_time_filter(t, comments, Comment)
+ next_exists = comments.count()
comments = sort_objects(sort, comments, Comment)
-
- comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE + 1).all()
- return [x[0] for x in comments]
+
+ comments = comments.offset(PAGE_SIZE * (page - 1)).limit(PAGE_SIZE).all()
+ return [x.id for x in comments], next_exists
@app.get("/comments")
@limiter.limit(DEFAULT_RATELIMIT)
@@ -221,7 +224,7 @@ def all_comments(v:User):
try: lt=int(request.values.get("before", 0))
except: lt=0
- idlist = comment_idlist(v=v,
+ idlist, next_exists = comment_idlist(v=v,
page=page,
sort=sort,
t=t,
@@ -230,8 +233,6 @@ def all_comments(v:User):
)
comments = get_comments(idlist, v=v)
- next_exists = len(idlist) > PAGE_SIZE
- idlist = idlist[:PAGE_SIZE]
if v.client: return {"data": [x.json(g.db) for x in comments]}
- return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists)
+ return render_template("home_comments.html", v=v, sort=sort, t=t, page=page, comments=comments, standalone=True, next_exists=next_exists, size = PAGE_SIZE)
diff --git a/files/templates/home.html b/files/templates/home.html
index 693517188..195f651d0 100644
--- a/files/templates/home.html
+++ b/files/templates/home.html
@@ -154,65 +154,7 @@
{% block pagenav %}
{% if listing %}
-
+ {% include "pagination.html" %}
{% endif %}
{% if request.path == '/' and v %}
diff --git a/files/templates/home_comments.html b/files/templates/home_comments.html
index 8b52f1083..2326bb9d0 100644
--- a/files/templates/home_comments.html
+++ b/files/templates/home_comments.html
@@ -67,22 +67,5 @@
{% endblock %}
{% block pagenav %}
-
+{% include "pagination.html" %}
{% endblock %}
diff --git a/files/templates/pagination.html b/files/templates/pagination.html
new file mode 100644
index 000000000..7a0a38862
--- /dev/null
+++ b/files/templates/pagination.html
@@ -0,0 +1,59 @@
+