Przeglądaj źródła

Improved config type

Taichi Masuyama 4 lat temu
rodzic
commit
d398db1c04

+ 4 - 4
packages/app/src/server/service/config-loader.ts

@@ -172,11 +172,11 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type:    ValueType.BOOLEAN,
     type:    ValueType.BOOLEAN,
     default: false,
     default: false,
   },
   },
-  V5_INDEX_NORMALIZATION_STATUS: {
+  IS_V5_INDEX_NORMALIZATION_IN_PROGRESS: {
     ns:      'crowi',
     ns:      'crowi',
-    key:     'app:v5IndexNormalizationStatus',
-    type:    ValueType.STRING,
-    default: 'processable',
+    key:     'app:isV5IndexNormalizationInProgress',
+    type:    ValueType.BOOLEAN,
+    default: false,
   },
   },
   IS_V5_COMPATIBLE: {
   IS_V5_COMPATIBLE: {
     ns:      'crowi',
     ns:      'crowi',

+ 8 - 10
packages/app/src/server/service/page.js

@@ -865,14 +865,14 @@ class PageService {
     }
     }
   }
   }
 
 
-  async _setV5IndexNormalizationStatus(status) {
+  async _setIsV5IndexNormalizationInProgress(status) {
     try {
     try {
       await this.crowi.configManager.updateConfigsInTheSameNamespace('crowi', {
       await this.crowi.configManager.updateConfigsInTheSameNamespace('crowi', {
-        'app:v5IndexNormalizationStatus': status,
+        'app:isV5IndexNormalizationInProgress': status,
       });
       });
     }
     }
     catch (err) {
     catch (err) {
-      logger.error(`Failed to update app:v5IndexNormalizationStatus to ${status} .`);
+      logger.error(`Failed to update app:isV5IndexNormalizationInProgress to ${status} .`);
       throw err;
       throw err;
     }
     }
   }
   }
@@ -908,28 +908,26 @@ class PageService {
 
 
   async v5InitialMigration(grant) {
   async v5InitialMigration(grant) {
     // const socket = this.crowi.socketIoService.getAdminSocket();
     // const socket = this.crowi.socketIoService.getAdminSocket();
-    const status = this.crowi.configManager.getConfig('crowi', 'app:v5IndexNormalizationStatus');
+    const isProcessing = this.crowi.configManager.getConfig('crowi', 'app:isV5IndexNormalizationInProgress');
 
 
     // avoid re-running many times
     // avoid re-running many times
-    const isProcessing = status === 'processing';
     if (isProcessing) {
     if (isProcessing) {
       return;
       return;
     }
     }
 
 
     const isUnique = await this._isPagePathIndexUnique();
     const isUnique = await this._isPagePathIndexUnique();
-    const isProcessable = status === 'processable' || status == null;
 
 
     // drop unique index first
     // drop unique index first
-    if (isUnique && isProcessable) {
-      await this._setV5IndexNormalizationStatus('processing');
+    if (isUnique) {
+      await this._setIsV5IndexNormalizationInProgress(true);
       try {
       try {
         await this._v5NormalizeIndex();
         await this._v5NormalizeIndex();
-        await this._setV5IndexNormalizationStatus('processable');
+        await this._setIsV5IndexNormalizationInProgress(false);
       }
       }
       catch (err) {
       catch (err) {
         logger.error('V5 index normalization failed.', err);
         logger.error('V5 index normalization failed.', err);
         // socket.emit('v5IndexNormalizationFailed', { error: err.message });
         // socket.emit('v5IndexNormalizationFailed', { error: err.message });
-        await this._setV5IndexNormalizationStatus('processable');
+        await this._setIsV5IndexNormalizationInProgress(false);
         throw err;
         throw err;
       }
       }
     }
     }