From: Aaron Schulz Date: Tue, 23 Aug 2016 00:13:33 +0000 (-0700) Subject: Move invalidatePages() to new PurgeJobUtils class X-Git-Tag: 1.31.0-rc.0~5961 X-Git-Url: http://git.cyclocoop.org/%24image?a=commitdiff_plain;h=f16eb73ecfe789277da4e9f809d1282c8e00c4e2;p=lhc%2Fweb%2Fwiklou.git Move invalidatePages() to new PurgeJobUtils class This does not really belong in SqlDataUpdate. Change-Id: I7166e50696483371f95db3a8b6bce44b0f866ccd --- diff --git a/autoload.php b/autoload.php index 330ebc4d5b..5457d2a610 100644 --- a/autoload.php +++ b/autoload.php @@ -1096,6 +1096,7 @@ $wgAutoloadLocalClasses = [ 'PurgeAction' => __DIR__ . '/includes/actions/PurgeAction.php', 'PurgeChangedFiles' => __DIR__ . '/maintenance/purgeChangedFiles.php', 'PurgeChangedPages' => __DIR__ . '/maintenance/purgeChangedPages.php', + 'PurgeJobUtils' => __DIR__ . '/includes/jobqueue/utils/PurgeJobUtils.php', 'PurgeList' => __DIR__ . '/maintenance/purgeList.php', 'PurgeOldText' => __DIR__ . '/maintenance/purgeOldText.php', 'PurgeParserCache' => __DIR__ . '/maintenance/purgeParserCache.php', diff --git a/includes/deferred/LinksUpdate.php b/includes/deferred/LinksUpdate.php index 4f40c3839d..5e02c5cc6c 100644 --- a/includes/deferred/LinksUpdate.php +++ b/includes/deferred/LinksUpdate.php @@ -304,7 +304,7 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate { * @param array $cats */ function invalidateCategories( $cats ) { - $this->invalidatePages( NS_CATEGORY, array_keys( $cats ) ); + PurgeJobUtils::invalidatePages( $this->mDb, NS_CATEGORY, array_keys( $cats ) ); } /** @@ -323,7 +323,7 @@ class LinksUpdate extends SqlDataUpdate implements EnqueueableDataUpdate { * @param array $images */ function invalidateImageDescriptions( $images ) { - $this->invalidatePages( NS_FILE, array_keys( $images ) ); + PurgeJobUtils::invalidatePages( $this->mDb, NS_FILE, array_keys( $images ) ); } /** diff --git a/includes/deferred/SqlDataUpdate.php b/includes/deferred/SqlDataUpdate.php index 9740cbe254..ff06915a77 100644 --- a/includes/deferred/SqlDataUpdate.php +++ b/includes/deferred/SqlDataUpdate.php @@ -98,53 +98,4 @@ abstract class SqlDataUpdate extends DataUpdate { $this->mHasTransaction = false; } } - - /** - * Invalidate the cache of a list of pages from a single namespace. - * This is intended for use by subclasses. - * - * @param int $namespace Namespace number - * @param array $dbkeys - */ - protected function invalidatePages( $namespace, array $dbkeys ) { - if ( $dbkeys === [] ) { - return; - } - - $dbw = $this->mDb; - $dbw->onTransactionPreCommitOrIdle( function() use ( $dbw, $namespace, $dbkeys ) { - /** - * Determine which pages need to be updated - * This is necessary to prevent the job queue from smashing the DB with - * large numbers of concurrent invalidations of the same page - */ - $now = $dbw->timestamp(); - $ids = $dbw->selectFieldValues( 'page', - 'page_id', - [ - 'page_namespace' => $namespace, - 'page_title' => $dbkeys, - 'page_touched < ' . $dbw->addQuotes( $now ) - ], - __METHOD__ - ); - - if ( $ids === [] ) { - return; - } - - /** - * Do the update - * We still need the page_touched condition, in case the row has changed since - * the non-locking select above. - */ - $dbw->update( 'page', - [ 'page_touched' => $now ], - [ - 'page_id' => $ids, - 'page_touched < ' . $dbw->addQuotes( $now ) - ], __METHOD__ - ); - } ); - } } diff --git a/includes/jobqueue/utils/PurgeJobUtils.php b/includes/jobqueue/utils/PurgeJobUtils.php new file mode 100644 index 0000000000..329bc23603 --- /dev/null +++ b/includes/jobqueue/utils/PurgeJobUtils.php @@ -0,0 +1,71 @@ +onTransactionPreCommitOrIdle( function() use ( $dbw, $namespace, $dbkeys ) { + // Determine which pages need to be updated. + // This is necessary to prevent the job queue from smashing the DB with + // large numbers of concurrent invalidations of the same page. + $now = $dbw->timestamp(); + $ids = $dbw->selectFieldValues( + 'page', + 'page_id', + [ + 'page_namespace' => $namespace, + 'page_title' => $dbkeys, + 'page_touched < ' . $dbw->addQuotes( $now ) + ], + __METHOD__ + ); + + if ( $ids === [] ) { + return; + } + + // Do the update. + // We still need the page_touched condition, in case the row has changed since + // the non-locking select above. + $dbw->update( + 'page', + [ 'page_touched' => $now ], + [ + 'page_id' => $ids, + 'page_touched < ' . $dbw->addQuotes( $now ) + ], + __METHOD__ + ); + } ); + } +}