mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #16314 from overleaf/em-migrate-docops-versions
Migrate doc versions from docOps to docs GitOrigin-RevId: 34b0130e9f0849b8e16f1febc38c78b55d51a4c1
This commit is contained in:
parent
64c512250d
commit
20bd57e9bd
1 changed files with 45 additions and 0 deletions
|
@ -0,0 +1,45 @@
|
|||
const { ReadPreference } = require('mongodb')
|
||||
|
||||
const BATCH_SIZE = parseInt(process.env.BATCH_SIZE || '1000', 10)
|
||||
|
||||
exports.tags = ['server-ce', 'server-pro', 'saas']
|
||||
|
||||
exports.migrate = async ({ db }) => {
|
||||
const records = db.docOps.find(
|
||||
{},
|
||||
{ readPreference: ReadPreference.secondaryPreferred }
|
||||
)
|
||||
|
||||
let docsProcessed = 0
|
||||
let batch = []
|
||||
for await (const record of records) {
|
||||
const docId = record.doc_id
|
||||
const version = record.version
|
||||
batch.push({
|
||||
updateOne: {
|
||||
filter: {
|
||||
_id: docId,
|
||||
version: { $exists: false },
|
||||
},
|
||||
update: { $set: { version } },
|
||||
},
|
||||
})
|
||||
if (batch.length >= BATCH_SIZE) {
|
||||
await db.docs.bulkWrite(batch, { ordered: false })
|
||||
batch = []
|
||||
}
|
||||
docsProcessed += 1
|
||||
if (docsProcessed % 100000 === 0) {
|
||||
console.log(`${docsProcessed} docs processed`)
|
||||
}
|
||||
}
|
||||
if (batch.length > 0) {
|
||||
await db.docs.bulkWrite(batch, { ordered: false })
|
||||
}
|
||||
}
|
||||
|
||||
exports.rollback = async ({ db }) => {
|
||||
// Nothing to do on rollback. We don't want to remove versions from the docs
|
||||
// collection because they might be more current than the ones in the docOps
|
||||
// collection.
|
||||
}
|
Loading…
Reference in a new issue