diff --git a/CHANGELOG-DEV.md b/CHANGELOG-DEV.md index 30c7dc31f3..4f621429a4 100644 --- a/CHANGELOG-DEV.md +++ b/CHANGELOG-DEV.md @@ -7,6 +7,7 @@ HumHub Changelog - Fix #5629: Better handling of legacy configuration file options - Fix #6931: Fix visibility of private spaces in the user notification settings - Enh #6757: Allow changing visibility of global content +- Fix #5419: Lock search index while reindexing 1.16.0-beta.1 (April 5, 2024) ----------------------------- diff --git a/protected/humhub/modules/content/jobs/SearchDeleteDocument.php b/protected/humhub/modules/content/jobs/SearchDeleteDocument.php index e8808b0cdb..23e8e72ed8 100644 --- a/protected/humhub/modules/content/jobs/SearchDeleteDocument.php +++ b/protected/humhub/modules/content/jobs/SearchDeleteDocument.php @@ -1,15 +1,19 @@ $this->contentId]); - if ($content) { - (new ContentSearchService($content))->delete(false); - } + return $this->getService()->run(function () { + $content = Content::findOne(['id' => $this->contentId]); + if ($content) { + (new ContentSearchService($content))->delete(false); + } + }); } + /** + * @inheritdoc + */ + public function canRetry($attempt, $error) + { + return $this->getService()->canRetry($attempt); + } + + public function getService(): SearchJobService + { + return new SearchJobService(); + } } diff --git a/protected/humhub/modules/content/jobs/SearchRebuildIndex.php b/protected/humhub/modules/content/jobs/SearchRebuildIndex.php index 9b05fdcf2f..81ac79dc62 100644 --- a/protected/humhub/modules/content/jobs/SearchRebuildIndex.php +++ b/protected/humhub/modules/content/jobs/SearchRebuildIndex.php @@ -10,6 +10,7 @@ namespace humhub\modules\content\jobs; use humhub\modules\content\models\Content; use humhub\modules\content\services\ContentSearchService; +use humhub\modules\content\services\SearchJobService; use humhub\modules\queue\interfaces\ExclusiveJobInterface; use humhub\modules\queue\LongRunningActiveJob; @@ -28,8 +29,23 @@ class SearchRebuildIndex extends LongRunningActiveJob implements ExclusiveJobInt */ public function run() { - foreach (Content::find()->each() as $content) { - (new ContentSearchService($content))->update(false); - } + return $this->getService()->run(function () { + foreach (Content::find()->each() as $content) { + (new ContentSearchService($content))->update(false); + } + }); + } + + /** + * @inheritdoc + */ + public function canRetry($attempt, $error) + { + return $this->getService()->canRetry($attempt); + } + + public function getService(): SearchJobService + { + return new SearchJobService(); } } diff --git a/protected/humhub/modules/content/jobs/SearchUpdateDocument.php b/protected/humhub/modules/content/jobs/SearchUpdateDocument.php index bf5445f97e..b3e28da03f 100644 --- a/protected/humhub/modules/content/jobs/SearchUpdateDocument.php +++ b/protected/humhub/modules/content/jobs/SearchUpdateDocument.php @@ -1,15 +1,19 @@ $this->contentId]); - if ($content) { - (new ContentSearchService($content))->update(false); - } + return $this->getService()->run(function () { + $content = Content::findOne(['id' => $this->contentId]); + if ($content) { + (new ContentSearchService($content))->update(false); + } + }); } + /** + * @inheritdoc + */ + public function canRetry($attempt, $error) + { + return $this->getService()->canRetry($attempt); + } + + public function getService(): SearchJobService + { + return new SearchJobService(); + } } diff --git a/protected/humhub/modules/content/services/SearchJobService.php b/protected/humhub/modules/content/services/SearchJobService.php new file mode 100644 index 0000000000..502c870ab9 --- /dev/null +++ b/protected/humhub/modules/content/services/SearchJobService.php @@ -0,0 +1,43 @@ +mutex->acquire(self::MUTEX_ID, $this->retryDelayInSeconds)) { + return false; + } + + try { + call_user_func($callable); + Yii::$app->mutex->release(self::MUTEX_ID); + } catch (\Exception $e) { + Yii::$app->mutex->release(self::MUTEX_ID); + return false; + } + + return true; + } + + /** + * @param $attempt Number of the current attempt + * @return bool + */ + public function canRetry($attempt): bool + { + return $attempt < $this->retryAttemptNum; + } +}