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

Merge pull request #5149 from weseek/imprv/7639-elasticsearch-reindex-on-boot

imprv: elasticsearch reindex on boot
Yuki Takei 4 лет назад
Родитель
Сommit
39065f2b2b

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

@@ -298,6 +298,12 @@ const ENV_VAR_NAME_TO_CONFIG_INFO = {
     type:    ValueType.BOOLEAN,
     type:    ValueType.BOOLEAN,
     default: false,
     default: false,
   },
   },
+  ELASTICSEARCH_REINDEX_ON_BOOT: {
+    ns:      'crowi',
+    key:     'app:elasticsearchReindexOnBoot',
+    type:    ValueType.BOOLEAN,
+    default: false,
+  },
   USE_ELASTICSEARCH_V6: {
   USE_ELASTICSEARCH_V6: {
     ns:      'crowi',
     ns:      'crowi',
     key:     'app:useElasticsearchV6',
     key:     'app:useElasticsearchV6',

+ 8 - 1
packages/app/src/server/service/search-delegator/elasticsearch.ts

@@ -47,6 +47,8 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
 
 
   isElasticsearchV6: boolean
   isElasticsearchV6: boolean
 
 
+  isElasticsearchReindexOnBoot: boolean
+
   elasticsearch: any
   elasticsearch: any
 
 
   client: any
   client: any
@@ -65,6 +67,7 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
     this.isElasticsearchV6 = this.configManager.getConfig('crowi', 'app:useElasticsearchV6');
     this.isElasticsearchV6 = this.configManager.getConfig('crowi', 'app:useElasticsearchV6');
 
 
     this.elasticsearch = this.isElasticsearchV6 ? elasticsearch6 : elasticsearch7;
     this.elasticsearch = this.isElasticsearchV6 ? elasticsearch6 : elasticsearch7;
+    this.isElasticsearchReindexOnBoot = this.configManager.getConfig('crowi', 'app:elasticsearchReindexOnBoot');
     this.client = null;
     this.client = null;
 
 
     // In Elasticsearch RegExp, we don't need to used ^ and $.
     // In Elasticsearch RegExp, we don't need to used ^ and $.
@@ -144,7 +147,11 @@ class ElasticsearchDelegator implements SearchDelegator<Data> {
   }
   }
 
 
   async init() {
   async init() {
-    return this.normalizeIndices();
+    const normalizeIndices = await this.normalizeIndices();
+    if (this.isElasticsearchReindexOnBoot) {
+      return this.rebuildIndex();
+    }
+    return normalizeIndices;
   }
   }
 
 
   /**
   /**