Răsfoiți Sursa

Fix #228: The error occurs on Elasticsearch when initial access

Yuki Takei 8 ani în urmă
părinte
comite
597054c7e3
1 a modificat fișierele cu 6 adăugiri și 3 ștergeri
  1. 6 3
      lib/util/search.js

+ 6 - 3
lib/util/search.js

@@ -207,13 +207,10 @@ SearchClient.prototype.deletePages = function(pages)
 SearchClient.prototype.addAllPages = function()
 {
   var self = this;
-  var offset = 0;
   var Page = this.crowi.model('Page');
   var cursor = Page.getStreamOfFindAll();
   var body = [];
 
-  var counter = 0;
-
   return new Promise(function(resolve, reject) {
     cursor.on('data', function (doc) {
       if (!doc.creator || !doc.revision || !self.shouldIndexed(doc)) {
@@ -228,6 +225,12 @@ SearchClient.prototype.addAllPages = function()
     }).on('close', function () {
       // all done
 
+      // return if body is empty
+      // see: https://github.com/weseek/crowi-plus/issues/228
+      if (body.length == 0) {
+        return resolve();
+      }
+
       // 最後に送信
       self.client.bulk({
         body: body,