Quellcode durchsuchen

Merge pull request #8335 from overleaf/msm-fix-reset-rev-script

Fixed `reset_incorrect_doc_revision.js` script

GitOrigin-RevId: 59448881e372ca7ca6f3b50f76cab5476279a1ab
Miguel Serrano vor 4 Jahren
Ursprung
Commit
c5f93bedea

+ 10 - 5
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_DESCENDING = process.env.BATCH_DESCENDING === 'true'
 const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 1000
 const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 1000
+const VERBOSE_LOGGING = process.env.VERBOSE_LOGGING === 'true'
 let BATCH_LAST_ID
 let BATCH_LAST_ID
 if (process.env.BATCH_LAST_ID) {
 if (process.env.BATCH_LAST_ID) {
   BATCH_LAST_ID = ObjectId(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
     maxId = nextBatch[nextBatch.length - 1]._id
     updated += nextBatch.length
     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') {
     if (typeof update === 'function') {
       await update(collection, nextBatch)
       await update(collection, nextBatch)

+ 7 - 6
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 DRY_RUN = process.env.DRY_RUN !== 'false'
 const PROJECT_ID = process.env.PROJECT_ID
 const PROJECT_ID = process.env.PROJECT_ID
 const VERBOSE_LOGGING = process.env.VERBOSE_LOGGING === 'true'
 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
 const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 500
 // persist fallback in order to keep batchedUpdate in-sync
 // persist fallback in order to keep batchedUpdate in-sync
 process.env.BATCH_SIZE = BATCH_SIZE
 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 = {
 const count = {
   projects: 0,
   projects: 0,
@@ -39,7 +40,7 @@ async function main() {
   } else {
   } else {
     await batchedUpdate(
     await batchedUpdate(
       'projects',
       'projects',
-      { 'overleaf.history.display': { $ne: false } },
+      { 'overleaf.history.display': { $ne: true } },
       processBatch,
       processBatch,
       projection,
       projection,
       options
       options