Chad has uploaded a new change for review.
https://gerrit.wikimedia.org/r/92825
Change subject: Rewrite SearchUpdate as a Job instead of a DeferredUpdate
......................................................................
Rewrite SearchUpdate as a Job instead of a DeferredUpdate
Change-Id: Icfd49da3a78d6c47b42c469fe38f43ec9434d3a3
---
M includes/AutoLoader.php
M includes/DefaultSettings.php
M includes/WikiPage.php
R includes/job/jobs/SearchUpdateJob.php
M includes/search/SearchEngine.php
M tests/phpunit/includes/search/SearchUpdateTest.php
6 files changed, 32 insertions(+), 43 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/25/92825/1
diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index dbba500..cdb09f4 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -686,6 +686,7 @@
'NullJob' => 'includes/job/jobs/NullJob.php',
'RefreshLinksJob' => 'includes/job/jobs/RefreshLinksJob.php',
'RefreshLinksJob2' => 'includes/job/jobs/RefreshLinksJob.php',
+ 'SearchUpdateJob' => 'includes/search/SearchUpdateJob.php',
'UploadFromUrlJob' => 'includes/job/jobs/UploadFromUrlJob.php',
'AssembleUploadChunksJob' =>
'includes/job/jobs/AssembleUploadChunksJob.php',
'PublishStashedFileJob' =>
'includes/job/jobs/PublishStashedFileJob.php',
@@ -909,7 +910,6 @@
'SearchResultSet' => 'includes/search/SearchEngine.php',
'SearchResultTooMany' => 'includes/search/SearchEngine.php',
'SearchSqlite' => 'includes/search/SearchSqlite.php',
- 'SearchUpdate' => 'includes/search/SearchUpdate.php',
'SqliteSearchResultSet' => 'includes/search/SearchSqlite.php',
'SqlSearchResultSet' => 'includes/search/SearchEngine.php',
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index d3c7b5f..1d91c1c 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -6060,7 +6060,8 @@
'uploadFromUrl' => 'UploadFromUrlJob',
'AssembleUploadChunks' => 'AssembleUploadChunksJob',
'PublishStashedFile' => 'PublishStashedFileJob',
- 'null' => 'NullJob'
+ 'null' => 'NullJob',
+ 'SearchUpdate' => 'SearchUpdateJob',
);
/**
diff --git a/includes/WikiPage.php b/includes/WikiPage.php
index 6d2d80c..cdb533f 100644
--- a/includes/WikiPage.php
+++ b/includes/WikiPage.php
@@ -2120,7 +2120,11 @@
}
DeferredUpdates::addUpdate( new SiteStatsUpdate( 0, 1, $good,
$total ) );
- DeferredUpdates::addUpdate( new SearchUpdate( $id, $title,
$content ) );
+ $searchUpdateJob = new SearchUpdateJob(
+ $title,
+ array( 'pageId' => $id, 'content' => $content )
+ );
+ JobQueueGroup::singleton()->push( $searchUpdateJob );
// If this is another user's talk page, update newtalk.
// Don't do this if $options['changed'] = false (null-edits)
nor if
@@ -2754,7 +2758,9 @@
$this->loadFromRow( false, self::READ_LATEST );
// Search engine
- DeferredUpdates::addUpdate( new SearchUpdate( $id,
$this->mTitle ) );
+ $searchUpdateJob = new SearchUpdateJob( $this->mTitle,
+ array( 'pageId' => $id ) );
+ JobQueueGroup::singleton()->push( $searchUpdateJob );
}
/**
diff --git a/includes/search/SearchUpdate.php
b/includes/job/jobs/SearchUpdateJob.php
similarity index 81%
rename from includes/search/SearchUpdate.php
rename to includes/job/jobs/SearchUpdateJob.php
index 82a413e..d4c7c2d 100644
--- a/includes/search/SearchUpdate.php
+++ b/includes/job/jobs/SearchUpdateJob.php
@@ -2,8 +2,6 @@
/**
* Search index updater
*
- * See deferred.txt
- *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
@@ -20,26 +18,20 @@
* http://www.gnu.org/copyleft/gpl.html
*
* @file
- * @ingroup Search
+ * @ingroup JobQueue
*/
/**
* Database independant search index updater
*
- * @ingroup Search
+ * @ingroup JobQueue
*/
-class SearchUpdate implements DeferrableUpdate {
+class SearchUpdateJob extends Job {
/**
* Page id being updated
* @var int
*/
- private $id = 0;
-
- /**
- * Title we're updating
- * @var Title
- */
- private $title;
+ private $pageId = 0;
/**
* Content of the page (not text)
@@ -56,40 +48,26 @@
* If a Content object, text will be gotten from it. String is for
back-compat.
* Passing false tells the backend to just update the title, not the
content
*/
- public function __construct( $id, $title, $c = false ) {
- if ( is_string( $title ) ) {
- $nt = Title::newFromText( $title );
- } else {
- $nt = $title;
- }
-
- if ( $nt ) {
- $this->id = $id;
- // is_string() check is back-compat for ApprovedRevs
- if ( is_string( $c ) ) {
- $this->content = new TextContent( $c );
- } else {
- $this->content = $c ?: false;
- }
- $this->title = $nt;
- } else {
- wfDebug( "SearchUpdate object created with invalid
title '$title'\n" );
- }
+ public function __construct( $title, $params = array(), $id = null ) {
+ parent::__construct( 'SearchUpdate', $title, $params, $id );
}
/**
* Perform actual update for the entry
*/
- public function doUpdate() {
+ public function run() {
global $wgDisableSearchUpdate;
- if ( $wgDisableSearchUpdate || !$this->id ) {
+ $this->pageId = isset( $this->params['pageId'] ) ?
$this->params['pageId'] : false;
+ $this->content = isset( $this->params['content'] ) ?
$this->params['content'] : false;
+
+ if ( $wgDisableSearchUpdate || !$this->pageId ) {
return;
}
wfProfileIn( __METHOD__ );
- $page = WikiPage::newFromId( $this->id, WikiPage::READ_LATEST );
+ $page = WikiPage::newFromId( $this->pageId,
WikiPage::READ_LATEST );
$indexTitle = Title::indexTitle( $this->title->getNamespace(),
$this->title->getText() );
foreach ( SearchEngine::getSearchTypes() as $type ) {
@@ -101,10 +79,10 @@
$normalTitle = $search->normalizeText( $indexTitle );
if ( $page === null ) {
- $search->delete( $this->id, $normalTitle );
+ $search->delete( $this->pageId, $normalTitle );
continue;
} elseif ( $this->content === false ) {
- $search->updateTitle( $this->id, $normalTitle );
+ $search->updateTitle( $this->pageId,
$normalTitle );
continue;
}
@@ -114,7 +92,7 @@
}
# Perform the actual update
- $search->update( $this->id, $normalTitle,
$search->normalizeText( $text ) );
+ $search->update( $this->pageId, $normalTitle,
$search->normalizeText( $text ) );
}
wfProfileOut( __METHOD__ );
@@ -124,6 +102,10 @@
* Clean text for indexing. Only really suitable for indexing in
databases.
* If you're using a real search engine, you'll probably want to
override
* this behavior and do something nicer with the original wikitext.
+ *
+ * @todo @fixme This belongs somewhere else, maybe SearchEngine? Maybe a
+ * shared SearchEngineDB that all database-backed ones can subclass?
Then
+ * we could get rid of the stupid textAlreadyUpdatedForIndex() hack
*/
public static function updateText( $text ) {
global $wgContLang;
diff --git a/includes/search/SearchEngine.php b/includes/search/SearchEngine.php
index 71c05d8..fc113bc 100644
--- a/includes/search/SearchEngine.php
+++ b/includes/search/SearchEngine.php
@@ -564,7 +564,7 @@
/**
* If an implementation of SearchEngine handles all of its own text
processing
- * in getTextFromContent() and doesn't require
SearchUpdate::updateText()'s
+ * in getTextFromContent() and doesn't require
SearchUpdateJob::updateText()'s
* rather silly handling, it should return true here instead.
*
* @return bool
diff --git a/tests/phpunit/includes/search/SearchUpdateTest.php
b/tests/phpunit/includes/search/SearchUpdateTest.php
index b913af8..ff8ff89 100644
--- a/tests/phpunit/includes/search/SearchUpdateTest.php
+++ b/tests/phpunit/includes/search/SearchUpdateTest.php
@@ -27,7 +27,7 @@
}
function updateText( $text ) {
- return trim( SearchUpdate::updateText( $text ) );
+ return trim( SearchUpdateJob::updateText( $text ) );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/92825
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Icfd49da3a78d6c47b42c469fe38f43ec9434d3a3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Chad <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits