Skip to content

Commit

Permalink
Merge pull request #1 from kyjus25/feat/query-limit
Browse files Browse the repository at this point in the history
[FEAT] Query Limit Header
  • Loading branch information
Digitalone1 authored Dec 24, 2022
2 parents 0473c0e + 292b5ff commit 3c095eb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/package_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/handlers/theme_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3c095eb

Please sign in to comment.