diff --git a/files/routes/front.py b/files/routes/front.py index 02f736802..413e530ca 100644 --- a/files/routes/front.py +++ b/files/routes/front.py @@ -167,6 +167,8 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' if v and v.admin_level < PERMS['USER_SHADOWBAN']: posts = posts.join(Post.author).filter(or_(User.id == v.id, User.shadowbanned == None)) + total = posts.count() + posts = sort_objects(sort, posts, Post) if v: size = v.frontsize or 0 @@ -180,13 +182,14 @@ def frontlist(v=None, sort="hot", page=1, t="all", ids_only=True, filter_words=' if SITE_NAME == 'WPD' and sort == "hot" and hole == None and not is_community: size -= 3 - posts1 = posts.filter(Post.hole.notin_(LIMITED_WPD_HOLES)) - total = posts1.count() - posts1 = posts1.offset(size * (page - 1)).limit(size).all() - posts2 = posts.filter(Post.hole.in_(LIMITED_WPD_HOLES)).offset(3 * (page - 1)).limit(3).all() - posts = posts1 + posts2 + posts1 = posts.filter(Post.hole.notin_(LIMITED_WPD_HOLES)).offset((size) * (page - 1)).limit(size).all() + if posts1: + posts2 = posts.filter(Post.hole.in_(LIMITED_WPD_HOLES)).offset(3 * (page - 1)).limit(3).all() + posts = posts1 + posts2 + else: + elapsed_pages = posts.filter(Post.hole.notin_(LIMITED_WPD_HOLES)).count() / size + posts = posts.filter(Post.hole.in_(LIMITED_WPD_HOLES)).offset(3 * elapsed_pages + size * (page - 1 - elapsed_pages)).limit(size).all() else: - total = posts.count() posts = posts.offset(size * (page - 1)).limit(size).all() if pins and page == 1 and not gt and not lt: