From b61ab62efb639c32fb55a18f32199cad96df5786 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Wed, 19 Aug 2020 11:11:39 +0200 Subject: [PATCH] Merge pull request #3120 from overleaf/jpa-batched-update-continue [scripts] batchedUpdate: add support for passing in the tail of the log GitOrigin-RevId: 50b573ec4f90026c3c2c660a5313fdd62817dbd9 --- services/web/scripts/helpers/batchedUpdate.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/services/web/scripts/helpers/batchedUpdate.js b/services/web/scripts/helpers/batchedUpdate.js index 3f489519af..1688383878 100644 --- a/services/web/scripts/helpers/batchedUpdate.js +++ b/services/web/scripts/helpers/batchedUpdate.js @@ -1,8 +1,12 @@ const { promisify } = require('util') -const { ReadPreference } = require('mongodb') +const { ReadPreference, ObjectId } = require('mongodb') const { getNativeDb } = require('../../app/src/infrastructure/Mongoose') const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 1000 +let BATCH_LAST_ID +if (process.env.BATCH_LAST_ID) { + BATCH_LAST_ID = ObjectId(process.env.BATCH_LAST_ID) +} async function getNextBatch(collection, query, maxId) { if (maxId) { @@ -33,7 +37,7 @@ async function batchedUpdate(collectionName, query, update) { let nextBatch let updated = 0 - let maxId + let maxId = BATCH_LAST_ID while ((nextBatch = await getNextBatch(collection, query, maxId)).length) { maxId = nextBatch[nextBatch.length - 1] updated += nextBatch.length