mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-06-06 15:49:01 +02:00
Merge pull request #26575 from overleaf/jpa-archived-state
[web] remove runtime migration for project.archived/trashed state GitOrigin-RevId: 69064878f3dfdcde3727a4e3eb555deb75c70588
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
import _ from 'lodash'
|
||||
import { db } from '../app/src/infrastructure/mongodb.js'
|
||||
import { batchedUpdate } from '@overleaf/mongo-utils/batchedUpdate.js'
|
||||
import { promiseMapWithLimit } from '@overleaf/promise-utils'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
const WRITE_CONCURRENCY = parseInt(process.env.WRITE_CONCURRENCY, 10) || 10
|
||||
|
||||
// $ node scripts/convert_archived_state.mjs FIRST,SECOND
|
||||
|
||||
async function main(STAGE) {
|
||||
for (const FIELD of ['archived', 'trashed']) {
|
||||
if (STAGE.includes('FIRST')) {
|
||||
await batchedUpdate(
|
||||
db.projects,
|
||||
{ [FIELD]: false },
|
||||
{
|
||||
$set: { [FIELD]: [] },
|
||||
}
|
||||
)
|
||||
|
||||
console.error('Done, with first part for field:', FIELD)
|
||||
}
|
||||
|
||||
if (STAGE.includes('SECOND')) {
|
||||
await batchedUpdate(
|
||||
db.projects,
|
||||
{ [FIELD]: true },
|
||||
async function performUpdate(nextBatch) {
|
||||
await promiseMapWithLimit(
|
||||
WRITE_CONCURRENCY,
|
||||
nextBatch,
|
||||
async project => {
|
||||
try {
|
||||
await upgradeFieldToArray({ project, FIELD })
|
||||
} catch (err) {
|
||||
console.error(project._id, err)
|
||||
throw err
|
||||
}
|
||||
}
|
||||
)
|
||||
},
|
||||
{
|
||||
_id: 1,
|
||||
owner_ref: 1,
|
||||
collaberator_refs: 1,
|
||||
readOnly_refs: 1,
|
||||
tokenAccessReadAndWrite_refs: 1,
|
||||
tokenAccessReadOnly_refs: 1,
|
||||
}
|
||||
)
|
||||
|
||||
console.error('Done, with second part for field:', FIELD)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function upgradeFieldToArray({ project, FIELD }) {
|
||||
return db.projects.updateOne(
|
||||
{ _id: project._id },
|
||||
{
|
||||
$set: { [FIELD]: getAllUserIds(project) },
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
function getAllUserIds(project) {
|
||||
return _.unionWith(
|
||||
[project.owner_ref],
|
||||
project.collaberator_refs,
|
||||
project.readOnly_refs,
|
||||
project.tokenAccessReadAndWrite_refs,
|
||||
project.tokenAccessReadOnly_refs,
|
||||
_objectIdEquals
|
||||
)
|
||||
}
|
||||
|
||||
function _objectIdEquals(firstVal, secondVal) {
|
||||
// For use as a comparator for unionWith
|
||||
return firstVal.toString() === secondVal.toString()
|
||||
}
|
||||
|
||||
if (fileURLToPath(import.meta.url) === process.argv[1]) {
|
||||
try {
|
||||
await main(process.argv.pop())
|
||||
process.exit(0)
|
||||
} catch (error) {
|
||||
console.error({ error })
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
export default main
|
||||
Reference in New Issue
Block a user