Forráskód Böngészése

Improved conditions

Taichi Masuyama 4 éve
szülő
commit
bf7975f623
1 módosított fájl, 14 hozzáadás és 13 törlés
  1. 14 13
      packages/app/src/server/service/page.js

+ 14 - 13
packages/app/src/server/service/page.js

@@ -753,21 +753,22 @@ class PageService {
     const Page = this.crowi.model('Page');
     const Page = this.crowi.model('Page');
     const indexStatus = await Page.aggregate([{ $indexStats: {} }]);
     const indexStatus = await Page.aggregate([{ $indexStats: {} }]);
     const pathIndexStatus = indexStatus.filter(status => status.name === 'path_1')?.[0];
     const pathIndexStatus = indexStatus.filter(status => status.name === 'path_1')?.[0];
-    const isUnique = pathIndexStatus?.spec?.unique;
+    const isPathIndexExists = pathIndexStatus != null;
+    const isUnique = isPathIndexExists && pathIndexStatus.spec?.unique === true;
 
 
-    if (isUnique === false) {
-      return this._setIsV5CompatibleTrue();
-    }
+    if (isUnique || !isPathIndexExists) {
+      try {
+        await this._v5NormalizeIndex(isPathIndexExists);
+      }
+      catch (err) {
+        logger.error('V5 index normalization failed.', err);
+        socket.emit('v5IndexNormalizationFailed', { error: err.message });
 
 
-    try {
-      await this._v5ModifyPagePathIndex(isUnique);
+        throw err;
+      }
     }
     }
-    catch (err) {
-      logger.error('V5 index modification failed.', err);
-      socket.emit('v5IndexModificationFailed', { error: err.message });
 
 
-      throw err;
-    }
+    await this._setIsV5CompatibleTrue();
   }
   }
 
 
   async _setIsV5CompatibleTrue() {
   async _setIsV5CompatibleTrue() {
@@ -906,10 +907,10 @@ class PageService {
 
 
   }
   }
 
 
-  async _v5ModifyPagePathIndex(isUnique) {
+  async _v5NormalizeIndex(isPathIndexExists) {
     const collection = mongoose.connection.collection('pages');
     const collection = mongoose.connection.collection('pages');
 
 
-    if (isUnique) {
+    if (isPathIndexExists) {
       try {
       try {
         // drop pages.path_1 indexes
         // drop pages.path_1 indexes
         await collection.dropIndex('path_1');
         await collection.dropIndex('path_1');