mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-07 20:31:06 -05:00
Merge pull request #3335 from overleaf/jpa-cmg-archived-script-logging
Update archiving script for re-run GitOrigin-RevId: 0251ca8d6f864f697395deac9470398519b704de
This commit is contained in:
parent
405a221187
commit
0450c52187
3 changed files with 34 additions and 21 deletions
|
@ -5,26 +5,34 @@ const WRITE_CONCURRENCY = parseInt(process.env.WRITE_CONCURRENCY, 10) || 10
|
|||
const { batchedUpdate } = require('./helpers/batchedUpdate')
|
||||
const { promiseMapWithLimit } = require('../app/src/util/promises')
|
||||
|
||||
// $ node scripts/convert_archived_state.js FIRST,SECOND
|
||||
const STAGE = process.argv.pop()
|
||||
|
||||
async function main() {
|
||||
await batchedUpdate(
|
||||
'projects',
|
||||
{ archived: false },
|
||||
{
|
||||
$set: { archived: [] },
|
||||
$unset: { trashed: '' } // lest any v1 trashed bits be left behind
|
||||
}
|
||||
)
|
||||
if (STAGE.includes('FIRST')) {
|
||||
await batchedUpdate(
|
||||
'projects',
|
||||
{ archived: false },
|
||||
{
|
||||
$set: { archived: [] }
|
||||
}
|
||||
)
|
||||
|
||||
console.log('Done, moving to archived projects')
|
||||
console.error('Done, with first part')
|
||||
}
|
||||
|
||||
await batchedUpdate('projects', { archived: true }, performUpdate, {
|
||||
_id: 1,
|
||||
owner_ref: 1,
|
||||
collaberator_refs: 1,
|
||||
readOnly_refs: 1,
|
||||
tokenAccessReadAndWrite_refs: 1,
|
||||
tokenAccessReadOnly_refs: 1
|
||||
})
|
||||
if (STAGE.includes('SECOND')) {
|
||||
await batchedUpdate('projects', { archived: true }, performUpdate, {
|
||||
_id: 1,
|
||||
owner_ref: 1,
|
||||
collaberator_refs: 1,
|
||||
readOnly_refs: 1,
|
||||
tokenAccessReadAndWrite_refs: 1,
|
||||
tokenAccessReadOnly_refs: 1
|
||||
})
|
||||
|
||||
console.error('Done, with second part')
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
|
@ -48,8 +56,7 @@ async function setArchived(collection, project) {
|
|||
return collection.updateOne(
|
||||
{ _id: project._id },
|
||||
{
|
||||
$set: { archived: archived },
|
||||
$unset: { trashed: '' } // lest any v1 trashed bits be left behind
|
||||
$set: { archived: archived }
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -43,13 +43,19 @@ async function batchedUpdate(collectionName, query, update, projection) {
|
|||
) {
|
||||
maxId = nextBatch[nextBatch.length - 1]._id
|
||||
updated += nextBatch.length
|
||||
console.log(JSON.stringify(nextBatch))
|
||||
console.log(
|
||||
`Running update on batch with ids ${JSON.stringify(
|
||||
nextBatch.map(entry => entry._id)
|
||||
)}`
|
||||
)
|
||||
|
||||
if (typeof update === 'function') {
|
||||
await update(collection, nextBatch)
|
||||
} else {
|
||||
await performUpdate(collection, nextBatch, update)
|
||||
}
|
||||
|
||||
console.error(`Completed batch ending ${maxId}`)
|
||||
}
|
||||
return updated
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ describe('ConvertArchivedState', function() {
|
|||
|
||||
beforeEach(function(done) {
|
||||
exec(
|
||||
'CONNECT_DELAY=1 node scripts/convert_archived_state.js',
|
||||
'CONNECT_DELAY=1 node scripts/convert_archived_state.js FIRST,SECOND',
|
||||
(error, stdout, stderr) => {
|
||||
console.log(stdout)
|
||||
console.error(stderr)
|
||||
|
|
Loading…
Reference in a new issue