From db83989d5d370ea6314213e0b560fd9591370773 Mon Sep 17 00:00:00 2001 From: Nicolas F Date: Tue, 2 Apr 2019 18:57:56 +0200 Subject: [PATCH] extensions: limit pagination to max num of pages --- nyaa/extensions.py | 2 ++ nyaa/search.py | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/nyaa/extensions.py b/nyaa/extensions.py index 48d84a5..8ac62ac 100644 --- a/nyaa/extensions.py +++ b/nyaa/extensions.py @@ -27,6 +27,8 @@ def fix_paginate(): total_query_count = count_query.scalar() else: total_query_count = self.count() + if max_page: + total_query_count = min(total_query_count, max_page * per_page) # Grab items on current page items = self.limit(per_page).offset((page - 1) * per_page).all() diff --git a/nyaa/search.py b/nyaa/search.py index 3e04613..aa94e0a 100644 --- a/nyaa/search.py +++ b/nyaa/search.py @@ -511,7 +511,6 @@ def search_db(term='', user=None, sort='id', order='desc', category='0_0', if len(item) >= 2: qpc.filter(FullTextSearch( item, models.TorrentNameSearch, FullTextMode.NATURAL)) - query, count_query = qpc.items # Sort and order if sort_column.class_ != models.Torrent: