Merge pull request #12277 from overleaf/jpa-cleanup-batched-update-interface
[web] simplify interface for custom update function in batchedUpdate GitOrigin-RevId: a00a24a012db400d4161de0bcefa2681206ab296
This commit is contained in:
@@ -2,6 +2,7 @@ const _ = require('lodash')
|
||||
|
||||
const WRITE_CONCURRENCY = parseInt(process.env.WRITE_CONCURRENCY, 10) || 10
|
||||
|
||||
const { db } = require('../app/src/infrastructure/mongodb')
|
||||
const { batchedUpdate } = require('./helpers/batchedUpdate')
|
||||
const { promiseMapWithLimit } = require('../app/src/util/promises')
|
||||
|
||||
@@ -25,13 +26,13 @@ async function main(STAGE) {
|
||||
await batchedUpdate(
|
||||
'projects',
|
||||
{ [FIELD]: true },
|
||||
async function performUpdate(collection, nextBatch) {
|
||||
async function performUpdate(nextBatch) {
|
||||
await promiseMapWithLimit(
|
||||
WRITE_CONCURRENCY,
|
||||
nextBatch,
|
||||
async project => {
|
||||
try {
|
||||
await upgradeFieldToArray({ collection, project, FIELD })
|
||||
await upgradeFieldToArray({ project, FIELD })
|
||||
} catch (err) {
|
||||
console.error(project._id, err)
|
||||
throw err
|
||||
@@ -67,8 +68,8 @@ if (require.main === module) {
|
||||
})
|
||||
}
|
||||
|
||||
async function upgradeFieldToArray({ collection, project, FIELD }) {
|
||||
return collection.updateOne(
|
||||
async function upgradeFieldToArray({ project, FIELD }) {
|
||||
return db.projects.updateOne(
|
||||
{ _id: project._id },
|
||||
{
|
||||
$set: { [FIELD]: getAllUserIds(project) },
|
||||
|
||||
Reference in New Issue
Block a user