X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdeferred%2FLinksUpdate.php;h=072c1e0d03b29e56e0a614a5933be798111662a5;hb=6547ac19a564774cb8c9beb879bbf21b30c78c2d;hp=464c908b40f5bed4ac365ded86b185056c187004;hpb=7ebf24be75fcdaecfcdd193e5ab58e351138035e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/deferred/LinksUpdate.php b/includes/deferred/LinksUpdate.php index 464c908b40..072c1e0d03 100644 --- a/includes/deferred/LinksUpdate.php +++ b/includes/deferred/LinksUpdate.php @@ -20,6 +20,7 @@ * @file */ +use Wikimedia\Rdbms\IDatabase; use MediaWiki\MediaWikiServices; use Wikimedia\ScopedCallback; @@ -145,7 +146,7 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate { # If the sortkey is longer then 255 bytes, # it truncated by DB, and then doesn't get # matched when comparing existing vs current - # categories, causing bug 25254. + # categories, causing T27254. # Also. substr behaves weird when given "". if ( $sortkey !== '' ) { $sortkey = substr( $sortkey, 0, 255 ); @@ -363,21 +364,24 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate { private function updateCategoryCounts( array $added, array $deleted ) { global $wgUpdateRowsPerQuery; + if ( !$added && !$deleted ) { + return; + } + + $wikiId = $this->getDB()->getWikiID(); $wp = WikiPage::factory( $this->mTitle ); - $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $lbf = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + // T163801: try to release any row locks to reduce contention + $lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'wiki' => $wikiId ] ); foreach ( array_chunk( array_keys( $added ), $wgUpdateRowsPerQuery ) as $addBatch ) { $wp->updateCategoryCounts( $addBatch, [], $this->mId ); - $factory->commitAndWaitForReplication( - __METHOD__, $this->ticket, [ 'wiki' => $this->getDB()->getWikiID() ] - ); + $lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'wiki' => $wikiId ] ); } foreach ( array_chunk( array_keys( $deleted ), $wgUpdateRowsPerQuery ) as $deleteBatch ) { $wp->updateCategoryCounts( [], $deleteBatch, $this->mId ); - $factory->commitAndWaitForReplication( - __METHOD__, $this->ticket, [ 'wiki' => $this->getDB()->getWikiID() ] - ); + $lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'wiki' => $wikiId ] ); } } @@ -398,7 +402,7 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate { private function incrTableUpdate( $table, $prefix, $deletions, $insertions ) { $services = MediaWikiServices::getInstance(); $bSize = $services->getMainConfig()->get( 'UpdateRowsPerQuery' ); - $factory = $services->getDBLoadBalancerFactory(); + $lbf = $services->getDBLoadBalancerFactory(); if ( $table === 'page_props' ) { $fromField = 'pp_page'; @@ -408,7 +412,7 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate { $deleteWheres = []; // list of WHERE clause arrays for each DB delete() call if ( $table === 'pagelinks' || $table === 'templatelinks' || $table === 'iwlinks' ) { - $baseKey = ( $table === 'iwlinks' ) ? 'iwl_prefix' : "{$prefix}_namespace"; + $baseKey = ( $table === 'iwlinks' ) ? 'iwl_prefix' : "{$prefix}_namespace"; $curBatchSize = 0; $curDeletionBatch = []; @@ -450,7 +454,7 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate { foreach ( $deleteWheres as $deleteWhere ) { $this->getDB()->delete( $table, $deleteWhere, __METHOD__ ); - $factory->commitAndWaitForReplication( + $lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'wiki' => $this->getDB()->getWikiID() ] ); } @@ -458,7 +462,7 @@ class LinksUpdate extends DataUpdate implements EnqueueableDataUpdate { $insertBatches = array_chunk( $insertions, $bSize ); foreach ( $insertBatches as $insertBatch ) { $this->getDB()->insert( $table, $insertBatch, __METHOD__, 'IGNORE' ); - $factory->commitAndWaitForReplication( + $lbf->commitAndWaitForReplication( __METHOD__, $this->ticket, [ 'wiki' => $this->getDB()->getWikiID() ] ); }