Demon has uploaded a new change for review.
https://gerrit.wikimedia.org/r/54712
Change subject: Wrap search results in PoolCounter
......................................................................
Wrap search results in PoolCounter
Change-Id: I344b48fad02a50cb2417ea38f1de0139e84a199e
---
M includes/PoolCounter.php
M includes/WikiPage.php
M includes/specials/SpecialSearch.php
M languages/messages/MessagesEn.php
M maintenance/language/messages.inc
5 files changed, 78 insertions(+), 26 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/12/54712/1
diff --git a/includes/PoolCounter.php b/includes/PoolCounter.php
index c6a3077..f27a177 100644
--- a/includes/PoolCounter.php
+++ b/includes/PoolCounter.php
@@ -141,6 +141,11 @@
protected $cacheable = false; //Does this override getCachedWork() ?
/**
+ * @var Status|bool
+ */
+ protected $error = false;
+
+ /**
* @param string $type The type of PoolCounter to use
* @param string $key Key that identifies the queue this work is placed
on
*/
@@ -176,10 +181,20 @@
* @return bool
*/
function error( $status ) {
+ $this->error = $status;
return false;
}
/**
+ * Get a Status object in case of error or false otherwise
+ *
+ * @return Status|bool
+ */
+ public function getError() {
+ return $this->error;
+ }
+
+ /**
* Log an error
*
* @param $status Status
diff --git a/includes/WikiPage.php b/includes/WikiPage.php
index 8d9d740..150c413 100644
--- a/includes/WikiPage.php
+++ b/includes/WikiPage.php
@@ -3324,11 +3324,6 @@
private $isDirty = false;
/**
- * @var Status|bool
- */
- private $error = false;
-
- /**
* Constructor
*
* @param $page Page
@@ -3369,15 +3364,6 @@
*/
public function getIsDirty() {
return $this->isDirty;
- }
-
- /**
- * Get a Status object in case of error or false otherwise
- *
- * @return Status|bool
- */
- public function getError() {
- return $this->error;
}
/**
@@ -3470,14 +3456,5 @@
$this->isDirty = true;
return true;
}
- }
-
- /**
- * @param $status Status
- * @return bool
- */
- function error( $status ) {
- $this->error = $status;
- return false;
}
}
diff --git a/includes/specials/SpecialSearch.php
b/includes/specials/SpecialSearch.php
index 6c40148..af3b7f8 100644
--- a/includes/specials/SpecialSearch.php
+++ b/includes/specials/SpecialSearch.php
@@ -252,10 +252,22 @@
// fetch search results
$rewritten = $search->replacePrefixes( $term );
- $titleMatches = $search->searchTitle( $rewritten );
- if( !( $titleMatches instanceof SearchResultTooMany ) ) {
- $textMatches = $search->searchText( $rewritten );
+ $poolSearchResults = new PoolWorkSearchResults( $search,
$rewritten );
+ if ( !$poolSearchResults->execute() ) {
+ $error = $poolSearchResults->getError();
+ if ( !$error->isGood() ) {
+ $this->getOutput()->clearHTML(); // for
release() errors
+ $this->getOutput()->enableClientCache( false );
+ $this->getOutput()->setRobotPolicy(
'noindex,nofollow' );
+
+ $errortext = $error->getWikiText( false,
'view-pool-error' );
+ $this->getOutput()->addWikiText( '<div
class="errorbox">' . $errortext . '</div>' );
+ }
+ wfProfileOut( __METHOD__ );
+ return;
}
+ $titleMatches = $poolSearchResults->getTitleMatches();
+ $textMatches = $poolSearchResults->getTextMatches();
// did you mean... suggestions
if( $textMatches && $textMatches->hasSuggestion() ) {
@@ -1165,3 +1177,45 @@
return 'redirects';
}
}
+
+class PoolWorkSearchResults extends PoolCounterWork {
+ /**
+ * @var SearchEngine
+ */
+ private $searchEngine;
+
+ /**
+ * @var String
+ */
+ private $searchTerm;
+
+ protected $cacheKey = 'mysearch';
+
+ /**
+ * Search results
+ */
+ private $titleMatches = null;
+ private $textMatches = null;
+
+ public function __construct( SearchEngine $engine, $term ) {
+ $this->searchEngine = $engine;
+ $this->searchTerm = $term;
+ parent::__construct( 'SearchResults', $this->cacheKey .
':searchterm:' . $term );
+ }
+
+ function doWork() {
+ $this->titleMatches = $this->searchEngine->searchTitle(
$this->searchTerm );
+ if( !( $this->titleMatches instanceof SearchResultTooMany ) ) {
+ $this->textMatches = $this->searchEngine->searchText(
$this->searchTerm );
+ }
+ return true;
+ }
+
+ public function getTitleMatches() {
+ return $this->titleMatches;
+ }
+
+ public function getTextMatches() {
+ return $this->textMatches;
+ }
+}
diff --git a/languages/messages/MessagesEn.php
b/languages/messages/MessagesEn.php
index bf95ed4..60f4db1 100644
--- a/languages/messages/MessagesEn.php
+++ b/languages/messages/MessagesEn.php
@@ -877,6 +877,11 @@
'pool-timeout' => 'Timeout waiting for the lock',
'pool-queuefull' => 'Pool queue is full',
'pool-errorunknown' => 'Unknown error',
+'search-pool-error' => 'Sorry, the servers are overloaded at the moment.
+Too many users are trying to search.
+Please wait a while before you try to access search.
+
+$1',
# All link text and link target definitions of links into project namespace
that get used by other message strings, with the exception of user group pages
(see grouppage) and the disambiguation template definition (see
disambiguations).
'aboutsite' => 'About {{SITENAME}}',
diff --git a/maintenance/language/messages.inc
b/maintenance/language/messages.inc
index db30ff7..03756f4 100644
--- a/maintenance/language/messages.inc
+++ b/maintenance/language/messages.inc
@@ -266,6 +266,7 @@
'pool-timeout',
'pool-queuefull',
'pool-errorunknown',
+ 'search-pool-error',
),
'links' => array(
'aboutsite',
--
To view, visit https://gerrit.wikimedia.org/r/54712
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I344b48fad02a50cb2417ea38f1de0139e84a199e
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Demon <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits