jenkins-bot has submitted this change and it was merged.

Change subject: Use a job to handle link updates.
......................................................................


Use a job to handle link updates.

The job is immediately executed if it is built in the cli but queued
otherwise.

Bug: 55848
Change-Id: I7bad34fef368a3177c7658d066092c86efec24ad
---
M CirrusSearch.php
A includes/CirrusSearchLinksUpdateJob.php
M includes/CirrusSearchUpdater.php
3 files changed, 71 insertions(+), 7 deletions(-)

Approvals:
  Aaron Schulz: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/CirrusSearch.php b/CirrusSearch.php
index 69d4aa0..ae2ffac 100644
--- a/CirrusSearch.php
+++ b/CirrusSearch.php
@@ -130,6 +130,7 @@
 $wgAutoloadClasses['CirrusSearch'] = $includes . 'CirrusSearch.body.php';
 $wgAutoloadClasses['CirrusSearchAnalysisConfigBuilder'] = $includes . 
'CirrusSearchAnalysisConfigBuilder.php';
 $wgAutoloadClasses['CirrusSearchConnection'] = $includes . 
'CirrusSearchConnection.php';
+$wgAutoloadClasses['CirrusSearchLinksUpdateJob'] = $includes . 
'CirrusSearchLinksUpdateJob.php';
 $wgAutoloadClasses['CirrusSearchFullTextResultsType'] = $includes . 
'CirrusSearchResultsType.php';
 $wgAutoloadClasses['CirrusSearchMappingConfigBuilder'] = $includes . 
'CirrusSearchMappingConfigBuilder.php';
 $wgAutoloadClasses['CirrusSearchReindexForkController'] = $includes . 
'CirrusSearchReindexForkController.php';
@@ -157,3 +158,8 @@
  * i18n
  */
 $wgExtensionMessagesFiles['CirrusSearch'] = __DIR__ . '/CirrusSearch.i18n.php';
+
+/**
+ * Jobs
+ */
+$wgJobClasses[ 'cirrusSearchLinksUpdate' ] = 'CirrusSearchLinksUpdateJob';
\ No newline at end of file
diff --git a/includes/CirrusSearchLinksUpdateJob.php 
b/includes/CirrusSearchLinksUpdateJob.php
new file mode 100644
index 0000000..7607971
--- /dev/null
+++ b/includes/CirrusSearchLinksUpdateJob.php
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Performs the appropriate updates to Elasticsearch after a LinksUpdate is
+ * completed.
+ *
+ * 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
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+class CirrusSearchLinksUpdateJob extends Job {
+       public function __construct( $title, $params, $id = 0 ) {
+               parent::__construct( 'cirrusSearchLinksUpdate', $title, 
$params, $id );
+       }
+
+       public function run() {
+               if ( $this->params[ 'titleNeedsUpdate' ] ) {
+                       CirrusSearchUpdater::updateFromTitle( $this->title );
+               }
+               CirrusSearchUpdater::updateLinkedArticles( $this->params[ 
'addedLinks' ],
+                       $this->params[ 'removedLinks' ] );
+       }
+}
diff --git a/includes/CirrusSearchUpdater.php b/includes/CirrusSearchUpdater.php
index cca0db8..db1c6a5 100644
--- a/includes/CirrusSearchUpdater.php
+++ b/includes/CirrusSearchUpdater.php
@@ -89,12 +89,36 @@
 
        /**
         * Hooked to update the search index for pages when templates that they 
include are changed
-        * and to kick off updating linked articles.
+        * and to update the link counts on newly linked or unlinked articles.  
These updates are
+        * all performed on the job queue.  If this is called in a web process 
then this adds the
+        * appropriate job to the queue.  If this is called from a cli process 
then this just
+        * immediately executes the job.
         * @param $linksUpdate LinksUpdate
         */
        public static function linksUpdateCompletedHook( $linksUpdate ) {
-               self::updateFromTitle( $linksUpdate->getTitle() );
-               self::updateLinkedArticles( $linksUpdate );
+               $inCli = PHP_SAPI == 'cli';
+               // In the web process the title update will be taken care of by 
the SearchEngine infrastructure
+               // so no need to update it in the job.
+               $titleNeedsUpdate = $inCli;
+               $addedLinks = $linksUpdate->getAddedLinks();
+               $removedLinks = $linksUpdate->getRemovedLinks();
+               if ( !$titleNeedsUpdate && count( $addedLinks ) === 0 && count( 
$removedLinks ) === 0 ) {
+                       // Nothing to do so no sense in going any further.
+                       return;
+               }
+               $job = new CirrusSearchLinksUpdateJob( 
$linksUpdate->getTitle(), array(
+                       'addedLinks' => $addedLinks,
+                       'removedLinks' => $removedLinks,
+                       'titleNeedsUpdate' => $titleNeedsUpdate,
+               ) );
+               if ( $inCli ) {
+                       // We are already on the cli (probably already running 
jobs) then there is no reason
+                       // to fork this job from the hook - just run them right 
now.
+                       $job->run();
+               } else {
+                       // We're in a web process so we should push this job on 
the queue and get to it later.
+                       JobQueueGroup::singleton()->push( $job );
+               }
        }
 
        /**
@@ -322,14 +346,15 @@
 
        /**
         * Update the search index for articles linked from this article.  Just 
updates link counts.
-        * @param $linksUpdate LinksUpdate
+        * @param $addedLinks array of Titles added to the page
+        * @param $removedLinks array of Titles removed from the page
         */
-       private static function updateLinkedArticles( $linksUpdate ) {
+       public static function updateLinkedArticles( $addedLinks, $removedLinks 
) {
                global $wgCirrusSearchLinkedArticlesToUpdate, 
$wgCirrusSearchUnlinkedArticlesToUpdate;
 
                $titles = array_merge(
-                       self::pickFromArray( $linksUpdate->getAddedLinks(), 
$wgCirrusSearchLinkedArticlesToUpdate ),
-                       self::pickFromArray( $linksUpdate->getRemovedLinks(), 
$wgCirrusSearchUnlinkedArticlesToUpdate )
+                       self::pickFromArray( $addedLinks, 
$wgCirrusSearchLinkedArticlesToUpdate ),
+                       self::pickFromArray( $removedLinks, 
$wgCirrusSearchUnlinkedArticlesToUpdate )
                );
                $pages = array();
                foreach ( $titles as $title ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/92643
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I7bad34fef368a3177c7658d066092c86efec24ad
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <[email protected]>
Gerrit-Reviewer: Aaron Schulz <[email protected]>
Gerrit-Reviewer: Chad <[email protected]>
Gerrit-Reviewer: Manybubbles <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to