Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions components/nocodb/nocodb.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,20 @@
let lastPage, count = 0;
args.params = {
...args.params,
page: 1,
offset: 0,
limit: 1000

Check failure on line 126 in components/nocodb/nocodb.app.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

Missing trailing comma
};
do {
const {
list, pageInfo,
} = await fn(args);
for (const item of list) {
args.params.offset++;
Copy link
Contributor

@coderabbitai coderabbitai bot Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the offset increment logic.

The current implementation increments the offset for each item yielded. This is incorrect for pagination purposes, as it will cause the next API call to skip items.

Replace the line:

args.params.offset++;

with:

// This line should be moved outside the for loop
args.params.offset += list.length;

This change ensures that the offset is incremented by the number of items retrieved in each API call, maintaining correct pagination.

Copy link
Contributor Author

@LucBerge LucBerge Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai Performing args.params.offset++ in the for loop or args.params.offset += list.length outside the loop is the exact same thing.

It is even better to do args.params.offset++ because in case the if (max && ++count === max) condition is met, offset is incremented by the correct number of rows returned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai Performing args.params.offset++ in the for loop or args.params.offset += list.length outside the loop is the exact same thing.

It is even better to do args.params.offset++ because in case the if (max && ++count === max) condition is met, offset is incremented by the correct number of rows returned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@LucBerge, you're right. Incrementing args.params.offset within the loop ensures the offset accurately reflects the number of items processed, especially when a max limit is specified. Thank you for the clarification. I'll note this for future reviews.


✏️ Learnings added
Learnt from: LucBerge
PR: PipedreamHQ/pipedream#14080
File: components/nocodb/nocodb.app.mjs:133-133
Timestamp: 2024-09-25T16:13:11.336Z
Learning: When implementing pagination with an offset, incrementing `args.params.offset` within the loop ensures correct tracking of the offset, particularly when a maximum count limit (`max`) is used.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

yield item;
if (max && ++count === max) {
return;
}
}
args.params.page++;
lastPage = !pageInfo.isLastPage;
} while (lastPage);
},
Expand Down
Loading