diff --git a/services/web/scripts/history/upgrade_none_with_conversion_if_sl_history.js b/services/web/scripts/history/upgrade_none_with_conversion_if_sl_history.js index 63cfb43bc1..cdd2d08625 100644 --- a/services/web/scripts/history/upgrade_none_with_conversion_if_sl_history.js +++ b/services/web/scripts/history/upgrade_none_with_conversion_if_sl_history.js @@ -1,4 +1,4 @@ -const SCRIPT_VERSION = 2 +const SCRIPT_VERSION = 3 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 @@ -68,13 +68,16 @@ async function processProject(project) { if (INTERRUPT) { return } - // skip safety check if we want to retry failed upgrades - if (!RETRY_FAILED) { - if (project.overleaf && project.overleaf.history) { - if ( - project.overleaf.history.conversionFailed || - project.overleaf.history.upgradeFailed - ) { + if (project.overleaf && project.overleaf.history) { + // projects we're upgrading like this should never have a history id + if (project.overleaf.history.id) { + return + } + if ( + project.overleaf.history.conversionFailed || + project.overleaf.history.upgradeFailed + ) { + if (!RETRY_FAILED) { // we don't want to attempt upgrade on projects // that have been previously attempted and failed return @@ -174,7 +177,11 @@ async function main() { } await batchedUpdate( 'projects', - { 'overleaf.history.id': { $exists: false } }, + // we originally used + // 'overleaf.history.id': { $exists: false } + // but display false is indexed and contains all the above, + // it can be faster to skip projects with a history ID than to use a query + { 'overleaf.history.display': { $ne: true } }, processBatch, projection, options diff --git a/services/web/scripts/history/upgrade_none_without_conversion_if_no_sl_history.js b/services/web/scripts/history/upgrade_none_without_conversion_if_no_sl_history.js index 69c799ec97..18df1a0882 100644 --- a/services/web/scripts/history/upgrade_none_without_conversion_if_no_sl_history.js +++ b/services/web/scripts/history/upgrade_none_without_conversion_if_no_sl_history.js @@ -1,4 +1,4 @@ -const SCRIPT_VERSION = 2 +const SCRIPT_VERSION = 3 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 @@ -69,15 +69,26 @@ async function processProject(project) { if (INTERRUPT) { return } - if (!RETRY_FAILED) { - if ( - project.overleaf && - project.overleaf.history && - project.overleaf.history.upgradeFailed - ) { + // If upgradeFailed, skip unless we're explicitly retrying failed upgrades + if ( + project.overleaf && + project.overleaf.history && + project.overleaf.history.upgradeFailed + ) { + if (RETRY_FAILED) { + return await doUpgradeForNoneWithoutConversion(project) + } else { return } } + // Skip any projects with a history ID, these are v1 + if ( + project.overleaf && + project.overleaf.history && + project.overleaf.history.id + ) { + return + } const anyDocHistory = await anyDocHistoryExists(project) if (anyDocHistory) { return @@ -187,7 +198,11 @@ async function main() { } await batchedUpdate( 'projects', - { 'overleaf.history.id': { $exists: false } }, + // we originally used + // 'overleaf.history.id': { $exists: false } + // but display false is indexed and contains all the above, + // plus we want to be able to retry failed upgrades with a history id + { 'overleaf.history.display': { $ne: true } }, processBatch, projection, options