From c5f93bedeab5283fd8b0de90437c833290ceb241 Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Wed, 8 Jun 2022 13:03:21 +0200 Subject: [PATCH] Merge pull request #8335 from overleaf/msm-fix-reset-rev-script Fixed `reset_incorrect_doc_revision.js` script GitOrigin-RevId: 59448881e372ca7ca6f3b50f76cab5476279a1ab --- services/web/scripts/helpers/batchedUpdate.js | 15 ++++++++++----- .../history/reset_incorrect_doc_revision.js | 13 +++++++------ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/services/web/scripts/helpers/batchedUpdate.js b/services/web/scripts/helpers/batchedUpdate.js index 5a98938d10..5100186368 100644 --- a/services/web/scripts/helpers/batchedUpdate.js +++ b/services/web/scripts/helpers/batchedUpdate.js @@ -3,6 +3,7 @@ const { db, waitForDb } = require('../../app/src/infrastructure/mongodb') const BATCH_DESCENDING = process.env.BATCH_DESCENDING === 'true' const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 1000 +const VERBOSE_LOGGING = process.env.VERBOSE_LOGGING === 'true' let BATCH_LAST_ID if (process.env.BATCH_LAST_ID) { BATCH_LAST_ID = ObjectId(process.env.BATCH_LAST_ID) @@ -78,11 +79,15 @@ async function batchedUpdate( ) { maxId = nextBatch[nextBatch.length - 1]._id updated += nextBatch.length - console.log( - `Running update on batch with ids ${JSON.stringify( - nextBatch.map(entry => entry._id) - )}` - ) + if (VERBOSE_LOGGING) { + console.log( + `Running update on batch with ids ${JSON.stringify( + nextBatch.map(entry => entry._id) + )}` + ) + } else { + console.error(`Running update on batch ending ${maxId}`) + } if (typeof update === 'function') { await update(collection, nextBatch) diff --git a/services/web/scripts/history/reset_incorrect_doc_revision.js b/services/web/scripts/history/reset_incorrect_doc_revision.js index 34b6099ae0..2f5d84d559 100644 --- a/services/web/scripts/history/reset_incorrect_doc_revision.js +++ b/services/web/scripts/history/reset_incorrect_doc_revision.js @@ -1,8 +1,3 @@ -const { ObjectId } = require('mongodb') -const { db, waitForDb } = require('../../app/src/infrastructure/mongodb') -const { batchedUpdate } = require('../helpers/batchedUpdate') -const { promiseMapWithLimit } = require('../../app/src/util/promises') - const DRY_RUN = process.env.DRY_RUN !== 'false' const PROJECT_ID = process.env.PROJECT_ID const VERBOSE_LOGGING = process.env.VERBOSE_LOGGING === 'true' @@ -11,6 +6,12 @@ const WRITE_CONCURRENCY = parseInt(process.env.WRITE_CONCURRENCY, 10) || 50 const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 500 // persist fallback in order to keep batchedUpdate in-sync process.env.BATCH_SIZE = BATCH_SIZE +process.env.VERBOSE_LOGGING = VERBOSE_LOGGING + +const { ObjectId } = require('mongodb') +const { db, waitForDb } = require('../../app/src/infrastructure/mongodb') +const { batchedUpdate } = require('../helpers/batchedUpdate') +const { promiseMapWithLimit } = require('../../app/src/util/promises') const count = { projects: 0, @@ -39,7 +40,7 @@ async function main() { } else { await batchedUpdate( 'projects', - { 'overleaf.history.display': { $ne: false } }, + { 'overleaf.history.display': { $ne: true } }, processBatch, projection, options