Просмотр исходного кода

Merge pull request #5752 from overleaf/tm-history-upgrade-failure-checks

Check for upgradeFailed before classifying/upgrading a project as v1

GitOrigin-RevId: 68776665762e87b640aab4c55a5e56062697912a
Thomas 4 лет назад
Родитель
Сommit
5c5f42df1f

+ 20 - 1
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) {

+ 9 - 1
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
   }

+ 10 - 1
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