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

- Assign the returned value in to a variable
- Check false first so can return early
- Implement reindex action to app/src/server/service.ts instead
- Make app:elasticsearchReindexOnBoot default value to false
- Remove ELASTICSEARCH_REINDEX_ON_BOOT on env.development
- Check and debug on both ES6 and ES7
- Remove elasticsearch.init since it's just run normalizeIndices

LuqmanHakim-Grune 4 лет назад
Родитель
Сommit
76ab48a267

+ 0 - 1
packages/app/.env.development

@@ -14,7 +14,6 @@ MONGO_URI="mongodb://mongo:27017/growi"
 ELASTICSEARCH_URI="http://elasticsearch:9200/growi"
 ELASTICSEARCH_REQUEST_TIMEOUT=15000
 ELASTICSEARCH_REJECT_UNAUTHORIZED=false
-ELASTICSEARCH_REINDEX_ON_BOOT=true
 USE_ELASTICSEARCH_V6=false
 HACKMD_URI="http://localhost:3010"
 HACKMD_URI_FOR_SERVER="http://hackmd:3000"

+ 1 - 18
packages/app/src/server/crowi/index.js

@@ -372,24 +372,7 @@ Crowi.prototype.setupPassport = async function() {
 };
 
 Crowi.prototype.setupSearcher = async function() {
-  const searchDelegatorLogger = loggerFactory('growi:service:search');
-
-  this.searchService = await new SearchService(this);
-
-  if (this.configManager.getConfig('crowi', 'app:elasticsearchReindexOnBoot')) {
-    searchDelegatorLogger.info('Reindex elasticsearch is running');
-    try {
-      this.searchService.rebuildIndex();
-    }
-    catch (err) {
-      // since rebuildIndex() will force to throw `error` in catch section and `finally` section won't be called,
-      // run normalize indices here anyway
-      this.searchService.normalizeIndices();
-    }
-  }
-  else {
-    searchDelegatorLogger.info('ELASTICSEARCH_REINDEX_ON_BOOT value is false, no reindex on boot');
-  }
+  this.searchService = new SearchService(this);
 };
 
 Crowi.prototype.setupMailer = async function() {

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

@@ -272,7 +272,7 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     ns:      'crowi',
     key:     'app:elasticsearchReindexOnBoot',
     type:    ValueType.BOOLEAN,
-    default: true,
+    default: false,
   },
   USE_ELASTICSEARCH_V6: {
     ns:      'crowi',

+ 0 - 4
packages/app/src/server/service/search-delegator/elasticsearch.ts

@@ -139,10 +139,6 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
     };
   }
 
-  async init() {
-    return this.normalizeIndices();
-  }
-
   /**
    * return Nodes Info
    * `cluster:monitor/nodes/info` privilege is required on ES

+ 19 - 1
packages/app/src/server/service/search.ts

@@ -54,6 +54,8 @@ class SearchService implements SearchQueryParser, SearchResolver {
 
   isErrorOccuredOnSearching: boolean | null
 
+  isElasticsearchReindexOnBoot: boolean
+
   fullTextSearchDelegator: any & SearchDelegator
 
   nqDelegators: {[key in SearchDelegatorName]: SearchDelegator}
@@ -74,8 +76,24 @@ class SearchService implements SearchQueryParser, SearchResolver {
       logger.error(err);
     }
 
+    this.isElasticsearchReindexOnBoot = this.configManager.getConfig('crowi', 'app:elasticsearchReindexOnBoot');
+
     if (this.isConfigured) {
-      this.fullTextSearchDelegator.init();
+      if (!this.isElasticsearchReindexOnBoot) {
+        logger.info('ELASTICSEARCH_REINDEX_ON_BOOT value is false, no reindex on boot');
+        this.normalizeIndices();
+      }
+      else {
+        logger.info('Reindex elasticsearch is running');
+        try {
+          this.rebuildIndex();
+          logger.info('Reindex elasticsearch done');
+        }
+        catch (err) {
+          logger.info(`Reindex elasticsearch fail ${err}`);
+        }
+      }
+
       this.registerUpdateEvent();
     }
   }