Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve eachBatch method #1179

Merged
merged 2 commits into from
Jun 12, 2020
Merged
Changes from all commits
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
25 changes: 15 additions & 10 deletions src/ParseQuery.js
Original file line number Diff line number Diff line change
Expand Up @@ -923,18 +923,23 @@ class ParseQuery {
}

let finished = false;
let previousResults = [];
return continueWhile(() => {
return !finished;
}, () => {
return query.find(findOptions).then((results) => {
return Promise.resolve(callback(results)).then(() => {
if (results.length >= query._limit) {
query.greaterThan('objectId', results[results.length - 1].id);
} else {
finished = true;
}
});
});
}, async () => {
const [results] = await Promise.all([
query.find(findOptions),
Promise.resolve(previousResults.length > 0 && callback(previousResults))
]);
if (results.length >= query._limit) {
query.greaterThan('objectId', results[results.length - 1].id);
previousResults = results;
} else if (results.length > 0) {
await Promise.resolve(callback(results));
finished = true;
} else {
finished = true;
}
});
}

Expand Down