From 5c5f42df1f0789893e4f1c72b17664b4fb1a0bf0 Mon Sep 17 00:00:00 2001 From: Thomas Date: Thu, 11 Nov 2021 16:09:54 +0100 Subject: [PATCH] Merge pull request #5752 from overleaf/tm-history-upgrade-failure-checks Check for upgradeFailed before classifying/upgrading a project as v1 GitOrigin-RevId: 68776665762e87b640aab4c55a5e56062697912a --- .../count_project_history_categories.js | 21 ++++++++++++++++++- ...conversion_if_created_after_fph_enabled.js | 10 ++++++++- ..._v1_without_conversion_if_no_sl_history.js | 11 +++++++++- 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/services/web/scripts/history/count_project_history_categories.js b/services/web/scripts/history/count_project_history_categories.js index 9f331991c0..6d375ea4b4 100644 --- a/services/web/scripts/history/count_project_history_categories.js +++ b/services/web/scripts/history/count_project_history_categories.js @@ -20,6 +20,7 @@ const COUNT = { NoneWithoutConversion: 0, NoneWithConversion: 0, NoneWithTemporaryHistory: 0, + HistoryUpgradeFailed: 0, } // Timestamp of when 'Enable history for SL in background' release @@ -35,12 +36,30 @@ async function processBatch(_, projects) { } async function processProject(project) { + if ( + project.overleaf && + project.overleaf.history && + project.overleaf.history.upgradeFailed + ) { + // a failed history upgrade might look like a v1 project, but history may be broken + COUNT.HistoryUpgradeFailed += 1 + return + } if ( project.overleaf && project.overleaf.history && project.overleaf.history.id ) { - if (project.overleaf.history.display) { + if (project.overleaf.history.upgradeFailed) { + COUNT.HistoryUpgradeFailed += 1 + if (VERBOSE_LOGGING) { + console.log( + `project ${ + project[VERBOSE_PROJECT_NAMES ? 'name' : '_id'] + } has a history upgrade failure recorded` + ) + } + } else if (project.overleaf.history.display) { // v2: full project history, do nothing, (query shoudln't include any, but we should stlll check?) COUNT.v2 += 1 if (VERBOSE_LOGGING) { diff --git a/services/web/scripts/history/upgrade_v1_without_conversion_if_created_after_fph_enabled.js b/services/web/scripts/history/upgrade_v1_without_conversion_if_created_after_fph_enabled.js index bcf58bd21b..48388b2a79 100644 --- a/services/web/scripts/history/upgrade_v1_without_conversion_if_created_after_fph_enabled.js +++ b/services/web/scripts/history/upgrade_v1_without_conversion_if_created_after_fph_enabled.js @@ -1,4 +1,4 @@ -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 @@ -41,6 +41,14 @@ async function processBatch(_, projects) { async function processProject(project) { // safety check + if ( + project.overleaf && + project.overleaf.history && + project.overleaf.history.upgradeFailed + ) { + // a failed history upgrade might look like a v1 project, but history may be broken + return + } if (!projectCreatedAfterFullProjectHistoryEnabled(project)) { return } diff --git a/services/web/scripts/history/upgrade_v1_without_conversion_if_no_sl_history.js b/services/web/scripts/history/upgrade_v1_without_conversion_if_no_sl_history.js index 9958b36152..0442281bcc 100644 --- a/services/web/scripts/history/upgrade_v1_without_conversion_if_no_sl_history.js +++ b/services/web/scripts/history/upgrade_v1_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 @@ -27,6 +27,15 @@ async function processBatch(_, projects) { } async function processProject(project) { + // safety check + if ( + project.overleaf && + project.overleaf.history && + project.overleaf.history.upgradeFailed + ) { + // a failed history upgrade might look like a v1 project, but history may be broken + return + } const preserveHistory = await shouldPreserveHistory(project) if (preserveHistory) { // if we need to preserve history, then we must bail out if history exists