|
|
@@ -1,8 +1,10 @@
|
|
|
-const SCRIPT_VERSION = 1
|
|
|
+const SCRIPT_VERSION = 2
|
|
|
const VERBOSE_LOGGING = process.env.VERBOSE_LOGGING === 'true'
|
|
|
const WRITE_CONCURRENCY = parseInt(process.env.WRITE_CONCURRENCY, 10) || 10
|
|
|
const BATCH_SIZE = parseInt(process.env.BATCH_SIZE, 10) || 100
|
|
|
const DRY_RUN = process.env.DRY_RUN !== 'false'
|
|
|
+const USE_QUERY_HINT = process.env.USE_QUERY_HINT !== 'false'
|
|
|
+const RETRY_FAILED = process.env.RETRY_FAILED === 'true'
|
|
|
const MAX_UPGRADES_TO_ATTEMPT =
|
|
|
parseInt(process.env.MAX_UPGRADES_TO_ATTEMPT, 10) || false
|
|
|
const MAX_FAILURES = parseInt(process.env.MAX_FAILURES, 10) || 50
|
|
|
@@ -26,6 +28,8 @@ console.log({
|
|
|
BATCH_SIZE,
|
|
|
MAX_UPGRADES_TO_ATTEMPT,
|
|
|
MAX_FAILURES,
|
|
|
+ USE_QUERY_HINT,
|
|
|
+ RETRY_FAILED,
|
|
|
})
|
|
|
|
|
|
const RESULT = {
|
|
|
@@ -65,6 +69,15 @@ async function processProject(project) {
|
|
|
if (INTERRUPT) {
|
|
|
return
|
|
|
}
|
|
|
+ if (!RETRY_FAILED) {
|
|
|
+ if (
|
|
|
+ project.overleaf &&
|
|
|
+ project.overleaf.history &&
|
|
|
+ project.overleaf.history.upgradeFailed
|
|
|
+ ) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
const anyDocHistory = await anyDocHistoryExists(project)
|
|
|
if (anyDocHistory) {
|
|
|
return
|
|
|
@@ -96,21 +109,20 @@ async function doUpgradeForNoneWithoutConversion(project) {
|
|
|
const historyId = await ProjectHistoryHandler.promises.getHistoryId(
|
|
|
projectId
|
|
|
)
|
|
|
- if (historyId != null) {
|
|
|
- return
|
|
|
- }
|
|
|
- const history = await HistoryManager.promises.initializeProject()
|
|
|
- if (history && history.overleaf_id) {
|
|
|
- await ProjectHistoryHandler.promises.setHistoryId(
|
|
|
- projectId,
|
|
|
- history.overleaf_id
|
|
|
- )
|
|
|
- await HistoryManager.promises.resyncProject(projectId, {
|
|
|
- force: true,
|
|
|
- origin: { kind: 'history-migration' },
|
|
|
- })
|
|
|
- await HistoryManager.promises.flushProject(projectId)
|
|
|
+ if (!historyId) {
|
|
|
+ const history = await HistoryManager.promises.initializeProject()
|
|
|
+ if (history && history.overleaf_id) {
|
|
|
+ await ProjectHistoryHandler.promises.setHistoryId(
|
|
|
+ projectId,
|
|
|
+ history.overleaf_id
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
+ await HistoryManager.promises.resyncProject(projectId, {
|
|
|
+ force: true,
|
|
|
+ origin: { kind: 'history-migration' },
|
|
|
+ })
|
|
|
+ await HistoryManager.promises.flushProject(projectId)
|
|
|
} catch (err) {
|
|
|
RESULT.failed += 1
|
|
|
console.error(`project ${project._id} FAILED with error: `, err)
|
|
|
@@ -132,6 +144,9 @@ async function doUpgradeForNoneWithoutConversion(project) {
|
|
|
'overleaf.history.upgradedAt': new Date(),
|
|
|
'overleaf.history.upgradeReason': `none-without-sl-history/${SCRIPT_VERSION}`,
|
|
|
},
|
|
|
+ $unset: {
|
|
|
+ 'overleaf.history.upgradeFailed': true,
|
|
|
+ },
|
|
|
}
|
|
|
)
|
|
|
}
|
|
|
@@ -166,8 +181,9 @@ async function main() {
|
|
|
_id: 1,
|
|
|
overleaf: 1,
|
|
|
}
|
|
|
- const options = {
|
|
|
- hint: { _id: 1 },
|
|
|
+ const options = {}
|
|
|
+ if (USE_QUERY_HINT) {
|
|
|
+ options.hint = { _id: 1 }
|
|
|
}
|
|
|
await batchedUpdate(
|
|
|
'projects',
|