Skip to content

Commit

Permalink
Make the pagination-checking logic clearer
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed Jul 19, 2021
1 parent df56a02 commit 3a4b10a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions data-serving/data-service/src/controllers/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ export class CasesController {
// Do a fetch of documents and another fetch in parallel for total documents
// count used in pagination.
const [docs, total] = await Promise.all([
sortedQuery.skip(limit * (page - 1)).limit(limit + 1),
sortedQuery.skip(limit * (page - 1)).limit(limit),
countQuery,
]);
logger.info('got results');
Expand All @@ -236,8 +236,7 @@ export class CasesController {
const reportedTotal = Math.min(total, countLimit);
// If we have more items than limit, add a response param
// indicating that there is more to fetch on the next page.
if (docs.length == limit + 1) {
docs.splice(limit);
if (total > limit * page) {
res.json({
cases: docs,
nextPage: page + 1,
Expand Down

0 comments on commit 3a4b10a

Please sign in to comment.