Enh: On search index rebuilding - use batch queries

This commit is contained in:
Lucas Bartholemy 2017-05-17 19:17:46 +02:00
parent dd648946ae
commit 9a90d5dc15
4 changed files with 17 additions and 11 deletions

View File

@ -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)
--------------------------------

View File

@ -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);
}
}
}
}

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}