diff --git a/services/web/scripts/migrate_audit_logs.js b/services/web/scripts/migrate_audit_logs.js index 4b205b6bac..0ce621558d 100644 --- a/services/web/scripts/migrate_audit_logs.js +++ b/services/web/scripts/migrate_audit_logs.js @@ -44,6 +44,18 @@ async function main(options) { }, { _id: 1, auditLog: 1 } ) + + // most projects are processed after its owner has been processed, but only those + // users with an existing `auditLog` have been taken into consideration, leaving + // some projects orphan. This batched update processes all remaining projects. + await batchedUpdate( + 'projects', + { auditLog: { $exists: true } }, + async (x, projects) => { + await processProjectsBatch(projects, options) + }, + { _id: 1, auditLog: 1 } + ) } } @@ -70,6 +82,16 @@ async function processUser(user, options) { projects.forEach(project => processProject(project, options)) } +async function processProjectsBatch(projects, options) { + await promiseMapWithLimit( + options.writeConcurrency, + projects, + async project => { + await processProject(project, options) + } + ) +} + async function processProject(project, options) { const entries = project.auditLog.map(log => ({ ...log,