From: aude Date: Wed, 2 Dec 2015 16:16:17 +0000 (+0100) Subject: Don't load WikiPage (w/ READ_LATEST) if search-update is not supported X-Git-Tag: 1.31.0-rc.0~8830 X-Git-Url: http://git.cyclocoop.org/%40spipnet%40?a=commitdiff_plain;h=70c501bbab7cb24d59a56a5c83bf7e19948ccadb;p=lhc%2Fweb%2Fwiklou.git Don't load WikiPage (w/ READ_LATEST) if search-update is not supported instead lazy load WikiPage, when needed. Change-Id: If67057b0b76f0f889ed498d8bbedaaeae3b2785d --- diff --git a/includes/deferred/SearchUpdate.php b/includes/deferred/SearchUpdate.php index f6c80f44dc..2abf02875e 100644 --- a/includes/deferred/SearchUpdate.php +++ b/includes/deferred/SearchUpdate.php @@ -38,6 +38,9 @@ class SearchUpdate implements DeferrableUpdate { /** @var Content|bool Content of the page (not text) */ private $content; + /** @var WikiPage **/ + private $page; + /** * Constructor * @@ -78,8 +81,6 @@ class SearchUpdate implements DeferrableUpdate { return; } - $page = WikiPage::newFromID( $this->id, WikiPage::READ_LATEST ); - foreach ( SearchEngine::getSearchTypes() as $type ) { $search = SearchEngine::create( $type ); if ( !$search->supports( 'search-update' ) ) { @@ -88,7 +89,7 @@ class SearchUpdate implements DeferrableUpdate { $normalTitle = $this->getNormalizedTitle( $search ); - if ( $page === null ) { + if ( $this->getLatestPage() === null ) { $search->delete( $this->id, $normalTitle ); continue; } elseif ( $this->content === false ) { @@ -172,6 +173,23 @@ class SearchUpdate implements DeferrableUpdate { return $text; } + /** + * Get WikiPage for the SearchUpdate $id using WikiPage::READ_LATEST + * and ensure using the same WikiPage object if there are multiple + * SearchEngine types. + * + * Returns null if a page has been deleted or is not found. + * + * @return WikiPage|null + */ + private function getLatestPage() { + if ( !isset( $this->page ) ) { + $this->page = WikiPage::newFromID( $this->id, WikiPage::READ_LATEST ); + } + + return $this->page; + } + /** * Get a normalized string representation of a title suitable for * including in a search index