From 9a90d5dc15bb36b8a5c8fe06e1316c5b373d386c Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Wed, 17 May 2017 19:17:46 +0200 Subject: [PATCH] Enh: On search index rebuilding - use batch queries --- protected/humhub/docs/CHANGELOG.md | 1 + protected/humhub/modules/content/Events.php | 13 +++++++------ protected/humhub/modules/space/Events.php | 6 ++++-- protected/humhub/modules/user/Events.php | 8 +++++--- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index 3f244becb0..37218db77b 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -13,6 +13,7 @@ HumHub Change Log - Fix #2571: last_login not set after registration direct login - Enh: Always trigger dom widget events for widget `fire` until `triggerDom` is set to false - Enh: Added `richtextPaste` event +- Enh: On search index rebuilding - use batch queries 1.2.0 (April 16, 2017) -------------------------------- diff --git a/protected/humhub/modules/content/Events.php b/protected/humhub/modules/content/Events.php index ab4cedd7b5..deade022a4 100644 --- a/protected/humhub/modules/content/Events.php +++ b/protected/humhub/modules/content/Events.php @@ -11,7 +11,6 @@ namespace humhub\modules\content; use Yii; use humhub\modules\content\models\Content; - /** * Events provides callbacks to handle events. * @@ -76,7 +75,7 @@ class Events extends \yii\base\Object $stackWidget->addWidget(widgets\DeleteLink::className(), ['content' => $content], ['sortOrder' => 100]); $stackWidget->addWidget(widgets\VisibilityLink::className(), ['contentRecord' => $content], ['sortOrder' => 250]); $stackWidget->addWidget(widgets\NotificationSwitchLink::className(), ['content' => $content], ['sortOrder' => 300]); - $stackWidget->addWidget(widgets\PermaLink::className(), ['content' => $content], ['sortOrder' => 400] ); + $stackWidget->addWidget(widgets\PermaLink::className(), ['content' => $content], ['sortOrder' => 400]); $stackWidget->addWidget(widgets\PinLink::className(), ['content' => $content], ['sortOrder' => 500]); $stackWidget->addWidget(widgets\ArchiveLink::className(), ['content' => $content], ['sortOrder' => 600]); } @@ -103,10 +102,12 @@ class Events extends \yii\base\Object */ public static function onSearchRebuild($event) { - foreach (Content::find()->all() as $content) { - $contentObject = $content->getPolymorphicRelation(); - if ($contentObject instanceof \humhub\modules\search\interfaces\Searchable) { - Yii::$app->search->add($contentObject); + foreach (Content::find()->batch() as $contents) { + foreach ($contents as $content) { + $contentObject = $content->getPolymorphicRelation(); + if ($contentObject instanceof \humhub\modules\search\interfaces\Searchable) { + Yii::$app->search->add($contentObject); + } } } } diff --git a/protected/humhub/modules/space/Events.php b/protected/humhub/modules/space/Events.php index 3970efca40..8c8fa29d06 100644 --- a/protected/humhub/modules/space/Events.php +++ b/protected/humhub/modules/space/Events.php @@ -28,8 +28,10 @@ class Events extends \yii\base\Object */ public static function onSearchRebuild($event) { - foreach (Space::find()->all() as $obj) { - Yii::$app->search->add($obj); + foreach (Space::find()->batch() as $spaces) { + foreach ($spaces as $space) { + Yii::$app->search->add($space); + } } } diff --git a/protected/humhub/modules/user/Events.php b/protected/humhub/modules/user/Events.php index d2afc56e9d..107f6cafa5 100644 --- a/protected/humhub/modules/user/Events.php +++ b/protected/humhub/modules/user/Events.php @@ -2,8 +2,8 @@ namespace humhub\modules\user; -use humhub\modules\content\models\ContentContainer; use Yii; +use humhub\modules\content\models\ContentContainer; use humhub\modules\user\models\User; use humhub\modules\user\models\Password; use humhub\modules\user\models\Profile; @@ -26,8 +26,10 @@ class Events extends \yii\base\Object */ public static function onSearchRebuild($event) { - foreach (models\User::find()->active()->all() as $obj) { - \Yii::$app->search->add($obj); + foreach (models\User::find()->active()->batch() as $users) { + foreach ($users as $user) { + Yii::$app->search->add($user); + } } }