[MediaWiki-commits] [Gerrit] mediawiki...GlobalUsage[master]: Avoid making DB replication lag in onLinksUpdateComplete()
jenkins-bot has submitted this change and it was merged. Change subject: Avoid making DB replication lag in onLinksUpdateComplete() .. Avoid making DB replication lag in onLinksUpdateComplete() Also removed old legacy code branch. Change-Id: Ib69dd3958b74d09ec137448af132712c6aa61083 --- M GlobalUsageHooks.php M GlobalUsage_body.php 2 files changed, 33 insertions(+), 24 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/GlobalUsageHooks.php b/GlobalUsageHooks.php index b766ade..778a0ff 100644 --- a/GlobalUsageHooks.php +++ b/GlobalUsageHooks.php @@ -14,7 +14,7 @@ * @param $linksUpdater LinksUpdate * @return bool */ - public static function onLinksUpdateComplete( $linksUpdater ) { + public static function onLinksUpdateComplete( LinksUpdate $linksUpdater ) { $title = $linksUpdater->getTitle(); // Create a list of locally existing images (DB keys) @@ -22,24 +22,11 @@ $localFiles = array(); $repo = RepoGroup::singleton()->getLocalRepo(); - if ( defined( 'FileRepo::NAME_AND_TIME_ONLY' ) ) { // MW 1.23 - $imagesInfo = $repo->findFiles( $images, FileRepo::NAME_AND_TIME_ONLY ); - foreach ( $imagesInfo as $dbKey => $info ) { - $localFiles[] = $dbKey; - if ( $dbKey !== $info['title'] ) { // redirect - $localFiles[] = $info['title']; - } - } - } else { - // Unrolling findFiles() here because pages with thousands of images trigger an OOM - foreach ( $images as $dbKey ) { - $file = $repo->findFile( $dbKey ); - if ( $file ) { - $localFiles[] = $dbKey; - if ( $file->getTitle()->getDBkey() !== $dbKey ) { // redirect - $localFiles[] = $file->getTitle()->getDBkey(); - } - } + $imagesInfo = $repo->findFiles( $images, FileRepo::NAME_AND_TIME_ONLY ); + foreach ( $imagesInfo as $dbKey => $info ) { + $localFiles[] = $dbKey; + if ( $dbKey !== $info['title'] ) { // redirect + $localFiles[] = $info['title']; } } $localFiles = array_values( array_unique( $localFiles ) ); @@ -106,6 +93,7 @@ */ public static function onArticleDeleteComplete( $article, $user, $reason, $id ) { $gu = self::getGlobalUsage(); + // @FIXME: avoid making DB replication lag $gu->deleteLinksFromPage( $id ); return true; diff --git a/GlobalUsage_body.php b/GlobalUsage_body.php index ca3fe1c..f9cd85e 100644 --- a/GlobalUsage_body.php +++ b/GlobalUsage_body.php @@ -1,6 +1,8 @@ $name ); } - $this->db->insert( 'globalimagelinks', $insert, __METHOD__, array( 'IGNORE' ) ); + + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ ); + foreach ( array_chunk( $insert, $wgUpdateRowsPerQuery ) as $insertBatch ) { + $this->db->insert( 'globalimagelinks', $insertBatch, __METHOD__, array( 'IGNORE' ) ); + $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket ); + } } /** @@ -58,8 +68,10 @@ ); $images = array(); - foreach ( $res as $row ) + foreach ( $res as $row ) { $images[] = $row->gil_to; + } + return $images; } @@ -69,15 +81,24 @@ * @param $id int Page id of the page * @param $to mixed File name(s) */ - public function deleteLinksFromPage( $id, $to = null ) { + public function deleteLinksFromPage( $id, array $to = null ) { + global $wgUpdateRowsPerQuery; + $where = array( 'gil_wiki' => $this->interwiki, 'gil_page' => $id ); if ( $to ) { - $where['gil_to'] = $to; + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ ); + foreach ( array_chunk( $to, $wgUpdateRowsPerQuery ) as $toBatch ) { +
[MediaWiki-commits] [Gerrit] mediawiki...GlobalUsage[master]: Avoid making DB replication lag in onLinksUpdateComplete()
Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/309973 Change subject: Avoid making DB replication lag in onLinksUpdateComplete() .. Avoid making DB replication lag in onLinksUpdateComplete() Also removed old legacy code branch. Change-Id: Ib69dd3958b74d09ec137448af132712c6aa61083 --- M GlobalUsageHooks.php M GlobalUsage_body.php 2 files changed, 33 insertions(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GlobalUsage refs/changes/73/309973/1 diff --git a/GlobalUsageHooks.php b/GlobalUsageHooks.php index b766ade..778a0ff 100644 --- a/GlobalUsageHooks.php +++ b/GlobalUsageHooks.php @@ -14,7 +14,7 @@ * @param $linksUpdater LinksUpdate * @return bool */ - public static function onLinksUpdateComplete( $linksUpdater ) { + public static function onLinksUpdateComplete( LinksUpdate $linksUpdater ) { $title = $linksUpdater->getTitle(); // Create a list of locally existing images (DB keys) @@ -22,24 +22,11 @@ $localFiles = array(); $repo = RepoGroup::singleton()->getLocalRepo(); - if ( defined( 'FileRepo::NAME_AND_TIME_ONLY' ) ) { // MW 1.23 - $imagesInfo = $repo->findFiles( $images, FileRepo::NAME_AND_TIME_ONLY ); - foreach ( $imagesInfo as $dbKey => $info ) { - $localFiles[] = $dbKey; - if ( $dbKey !== $info['title'] ) { // redirect - $localFiles[] = $info['title']; - } - } - } else { - // Unrolling findFiles() here because pages with thousands of images trigger an OOM - foreach ( $images as $dbKey ) { - $file = $repo->findFile( $dbKey ); - if ( $file ) { - $localFiles[] = $dbKey; - if ( $file->getTitle()->getDBkey() !== $dbKey ) { // redirect - $localFiles[] = $file->getTitle()->getDBkey(); - } - } + $imagesInfo = $repo->findFiles( $images, FileRepo::NAME_AND_TIME_ONLY ); + foreach ( $imagesInfo as $dbKey => $info ) { + $localFiles[] = $dbKey; + if ( $dbKey !== $info['title'] ) { // redirect + $localFiles[] = $info['title']; } } $localFiles = array_values( array_unique( $localFiles ) ); @@ -106,6 +93,7 @@ */ public static function onArticleDeleteComplete( $article, $user, $reason, $id ) { $gu = self::getGlobalUsage(); + // @FIXME: avoid making DB replication lag $gu->deleteLinksFromPage( $id ); return true; diff --git a/GlobalUsage_body.php b/GlobalUsage_body.php index ca3fe1c..f9cd85e 100644 --- a/GlobalUsage_body.php +++ b/GlobalUsage_body.php @@ -1,6 +1,8 @@ $name ); } - $this->db->insert( 'globalimagelinks', $insert, __METHOD__, array( 'IGNORE' ) ); + + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ ); + foreach ( array_chunk( $insert, $wgUpdateRowsPerQuery ) as $insertBatch ) { + $this->db->insert( 'globalimagelinks', $insertBatch, __METHOD__, array( 'IGNORE' ) ); + $lbFactory->commitAndWaitForReplication( __METHOD__, $ticket ); + } } /** @@ -58,8 +68,10 @@ ); $images = array(); - foreach ( $res as $row ) + foreach ( $res as $row ) { $images[] = $row->gil_to; + } + return $images; } @@ -69,15 +81,24 @@ * @param $id int Page id of the page * @param $to mixed File name(s) */ - public function deleteLinksFromPage( $id, $to = null ) { + public function deleteLinksFromPage( $id, array $to = null ) { + global $wgUpdateRowsPerQuery; + $where = array( 'gil_wiki' => $this->interwiki, 'gil_page' => $id ); if ( $to ) { - $where['gil_to'] = $to; + $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory(); + $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ ); + foreach (