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

Merge from crowi/crowi [62ed2a0]

# Conflicts:
#	lib/util/search.js
Yuki Takei 8 лет назад
Родитель
Сommit
c1837f7b1d
2 измененных файлов с 22 добавлено и 3 удалено
  1. 1 0
      lib/routes/login.js
  2. 21 3
      lib/util/search.js

+ 1 - 0
lib/routes/login.js

@@ -130,6 +130,7 @@ module.exports = function(crowi, app) {
         User.findUserByGoogleId(googleId, function(err, userData) {
           debug('findUserByGoogleId', err, userData);
           if (!userData) {
+            clearGoogleSession(req);
             return loginFailure(req, res);
           }
           return loginSuccess(req, res, userData);

+ 21 - 3
lib/util/search.js

@@ -210,15 +210,33 @@ SearchClient.prototype.addAllPages = function()
   var Page = this.crowi.model('Page');
   var cursor = Page.getStreamOfFindAll();
   var body = [];
+  var sent = 0;
+  var skipped = 0;
 
   return new Promise(function(resolve, reject) {
     cursor.on('data', function (doc) {
       if (!doc.creator || !doc.revision || !self.shouldIndexed(doc)) {
-        debug('Skipped', doc.path);
+        //debug('Skipped', doc.path);
+        skipped++;
         return ;
       }
 
       self.prepareBodyForCreate(body, doc);
+      //debug(body.length);
+      if (body.length > 2000) {
+        sent++;
+        debug('Sending request (seq, skipped)', sent, skipped);
+        self.client.bulk({
+          body: body,
+          requestTimeout: Infinity,
+        }).then(res => {
+          debug('addAllPages add anyway (items, errors, took): ', (res.items || []).length, res.errors, res.took)
+        }).catch(err => {
+          debug('addAllPages error on add anyway: ', err)
+        });
+
+        body = [];
+      }
     }).on('error', function (err) {
       // TODO: handle err
       debug('Error cursor:', err);
@@ -231,13 +249,13 @@ SearchClient.prototype.addAllPages = function()
         return resolve();
       }
 
-      // 最後に送信
+      // 最後にすべてを送信
       self.client.bulk({
         body: body,
         requestTimeout: Infinity,
       })
       .then(function(res) {
-        debug('Reponse from es:', res);
+        debug('Reponse from es (item length, errros, took):', (res.items || []).length, res.errors, res.took);
         return resolve(res);
       }).catch(function(err) {
         debug('Err from es:', err);