From 292b5ff95a197e47ee7b5f38588f4b08dd9ba246 Mon Sep 17 00:00:00 2001 From: Justin White Date: Sat, 24 Dec 2022 12:00:43 -0600 Subject: [PATCH] Add Query-Limit header to denote pagination limit --- src/database.js | 14 ++++++++------ src/handlers/package_handler.js | 2 ++ src/handlers/theme_handler.js | 2 ++ 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/database.js b/src/database.js index 8fb49b80..963ad4a5 100644 --- a/src/database.js +++ b/src/database.js @@ -1322,8 +1322,8 @@ async function simpleSearch(term, page, dir, sort, themes = false) { } const resultCount = command[0].query_result_count; - const quotient = Math.trunc(resultCount / paginated_amount); - const remainder = resultCount % paginated_amount; + const quotient = Math.trunc(resultCount / limit); + const remainder = resultCount % limit; const totalPages = quotient + (remainder > 0 ? 1 : 0); return { @@ -1332,7 +1332,8 @@ async function simpleSearch(term, page, dir, sort, themes = false) { pagination: { count: resultCount, page: (page < totalPages) ? page : totalPages, - total: totalPages + total: totalPages, + limit } }; } catch (err) { @@ -1438,8 +1439,8 @@ async function getSortedPackages(page, dir, method, themes = false) { `; const resultCount = command[0]?.query_result_count ?? 0; - const quotient = Math.trunc(resultCount / paginated_amount); - const remainder = resultCount % paginated_amount; + const quotient = Math.trunc(resultCount / limit); + const remainder = resultCount % limit; const totalPages = quotient + (remainder > 0 ? 1 : 0); return { @@ -1448,7 +1449,8 @@ async function getSortedPackages(page, dir, method, themes = false) { pagination: { count: resultCount, page: (page < totalPages) ? page : totalPages, - total: totalPages + total: totalPages, + limit } }; } catch (err) { diff --git a/src/handlers/package_handler.js b/src/handlers/package_handler.js index 476350dc..b390b093 100644 --- a/src/handlers/package_handler.js +++ b/src/handlers/package_handler.js @@ -76,6 +76,7 @@ async function getPackages(req, res) { res.append("Link", link); res.append("Query-Total", packages.pagination.count); + res.append("Query-Limit", packages.pagination.limit); res.status(200).json(packArray); logger.httpLog(req, res); @@ -352,6 +353,7 @@ async function getPackagesSearch(req, res) { res.append("Link", link); res.append("Query-Total", packs.pagination.count); + res.append("Query-Limit", packs.pagination.limit); res.status(200).json(packArray); logger.httpLog(req, res); diff --git a/src/handlers/theme_handler.js b/src/handlers/theme_handler.js index 2a414178..b0f59901 100644 --- a/src/handlers/theme_handler.js +++ b/src/handlers/theme_handler.js @@ -99,6 +99,7 @@ async function getThemes(req, res) { res.append("Link", link); res.append("Query-Total", packages.pagination.count); + res.append("Query-Limit", packages.pagination.limit); res.status(200).json(packArray); logger.httpLog(req, res); @@ -182,6 +183,7 @@ async function getThemesSearch(req, res) { res.append("Link", link); res.append("Query-Total", packs.pagination.count); + res.append("Query-Limit", packs.pagination.limit); res.status(200).json(packArray); logger.httpLog(req, res);