Skip to content

Commit

Permalink
Skip operations if no action on livechat migration (#11232)
Browse files Browse the repository at this point in the history
Closes #11231
  • Loading branch information
sampaiodiego authored and rodrigok committed Jun 25, 2018
1 parent 103fab1 commit 80d8aed
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions server/startup/migrations/v123.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@ async function migrateHistory(total, current) {
return result;
}, { insert: [], remove: [] });

const batch = Promise.all([
messageCollection.insertMany(actions.insert),
pageVisitedCollection.removeMany({ _id: { $in: actions.remove } })
]);
const ops = [];

if (actions.insert.length > 0) {
ops.push(messageCollection.insertMany(actions.insert));
}

if (actions.remove.length > 0) {
ops.push(pageVisitedCollection.removeMany({ _id: { $in: actions.remove } }));
}

const batch = Promise.all(ops);
if (actions.remove.length === batchSize) {
await batch;
return migrateHistory(total, current + batchSize);
Expand Down

0 comments on commit 80d8aed

Please sign in to comment.