Skip to content

Commit

Permalink
Refactor getAll method to use a single page variable and update pagin…
Browse files Browse the repository at this point in the history
…ation logic

- Updated the pagination logic to use a single `page` variable for both the initial response and the for loop.
- Changed the calculation of `lastPage` by dividing the total number by 100 instead of 25 to optimize the page count.
  • Loading branch information
demirgazetic committed Aug 1, 2024
1 parent 04bb879 commit 00404f6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/src/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ module.exports = {
initialResponse.data[type].constructor === Object
? Object.values(initialResponse.data[type])
: initialResponse.data[type];
let lastPage = Math.ceil(initialResponse.total / 25);
let lastPage = Math.ceil(initialResponse.total / 100);

const fetchPromises = [];
for (let p = 2; p <= lastPage; p++) {
fetchPromises.push(this.getPage(type, p, options));
for (page = 2; page <= lastPage; page++) {
fetchPromises.push(this.getPage(type, page, options));
}

const pageResponses = await Promise.all(fetchPromises);
Expand All @@ -116,5 +116,5 @@ module.exports = {
});

return allItems;
},
}
};

0 comments on commit 00404f6

Please sign in to comment.