From eb6bfc07000ba5f521edaaab30cdd35a40e28a07 Mon Sep 17 00:00:00 2001 From: Diego Sampaio Date: Fri, 22 Jun 2018 09:11:29 -0300 Subject: [PATCH] Skip operations if no action on livechat migration Closes #11231 --- server/startup/migrations/v123.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server/startup/migrations/v123.js b/server/startup/migrations/v123.js index e1e0b7b4fe1e3..eb866ee369111 100644 --- a/server/startup/migrations/v123.js +++ b/server/startup/migrations/v123.js @@ -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);