Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/312453

Change subject: Use provided transaction ticket in onLinksUpdateComplete()
......................................................................

Use provided transaction ticket in onLinksUpdateComplete()

Change-Id: I878fcb4a263e3e6291c7632a0ccd89d42179001d
---
M GlobalUsageHooks.php
M GlobalUsage_body.php
2 files changed, 12 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GlobalUsage 
refs/changes/53/312453/1

diff --git a/GlobalUsageHooks.php b/GlobalUsageHooks.php
index 778a0ff..b1363de 100644
--- a/GlobalUsageHooks.php
+++ b/GlobalUsageHooks.php
@@ -12,9 +12,10 @@
         * Hook to LinksUpdateComplete
         * Deletes old links from usage table and insert new ones.
         * @param $linksUpdater LinksUpdate
+        * @param int|null $ticket
         * @return bool
         */
-       public static function onLinksUpdateComplete( LinksUpdate $linksUpdater 
) {
+       public static function onLinksUpdateComplete( LinksUpdate 
$linksUpdater, $ticket = null ) {
                $title = $linksUpdater->getTitle();
 
                // Create a list of locally existing images (DB keys)
@@ -42,9 +43,9 @@
                $removed = array_diff( $existing, $missingFiles );
 
                // Add new usages and delete removed
-               $gu->insertLinks( $title, $added );
+               $gu->insertLinks( $title, $added, Title::GAID_FOR_UPDATE, 
$ticket );
                if ( $removed ) {
-                       $gu->deleteLinksFromPage( $articleId, $removed );
+                       $gu->deleteLinksFromPage( $articleId, $removed, $ticket 
);
                }
 
                return true;
diff --git a/GlobalUsage_body.php b/GlobalUsage_body.php
index f9cd85e..49f6229 100644
--- a/GlobalUsage_body.php
+++ b/GlobalUsage_body.php
@@ -27,8 +27,11 @@
         * @param $title Title Title of the page
         * @param $images array Array of db keys of images used
         * @param $pageIdFlags int
+        * @param $ticket int|null
         */
-       public function insertLinks( $title, $images, $pageIdFlags = 
Title::GAID_FOR_UPDATE ) {
+       public function insertLinks(
+               Title $title, array $images, $pageIdFlags = 
Title::GAID_FOR_UPDATE, $ticket = null
+       ) {
                global $wgUpdateRowsPerQuery;
 
                $insert = array();
@@ -44,7 +47,7 @@
                }
 
                $lbFactory = 
MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
-               $ticket = $lbFactory->getEmptyTransactionTicket( __METHOD__ );
+               $ticket = $ticket ?: $lbFactory->getEmptyTransactionTicket( 
__METHOD__ );
                foreach ( array_chunk( $insert, $wgUpdateRowsPerQuery ) as 
$insertBatch ) {
                        $this->db->insert( 'globalimagelinks', $insertBatch, 
__METHOD__, array( 'IGNORE' ) );
                        $lbFactory->commitAndWaitForReplication( __METHOD__, 
$ticket );
@@ -80,8 +83,9 @@
         *
         * @param $id int Page id of the page
         * @param $to mixed File name(s)
+        * @param $ticket int|null
         */
-       public function deleteLinksFromPage( $id, array $to = null ) {
+       public function deleteLinksFromPage( $id, array $to = null, $ticket = 
null ) {
                global $wgUpdateRowsPerQuery;
 
                $where = array(
@@ -90,7 +94,7 @@
                );
                if ( $to ) {
                        $lbFactory = 
MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
-                       $ticket = $lbFactory->getEmptyTransactionTicket( 
__METHOD__ );
+                       $ticket = $ticket ?: 
$lbFactory->getEmptyTransactionTicket( __METHOD__ );
                        foreach ( array_chunk( $to, $wgUpdateRowsPerQuery ) as 
$toBatch ) {
                                $where['gil_to'] = $toBatch;
                                $this->db->delete( 'globalimagelinks', $where, 
__METHOD__ );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I878fcb4a263e3e6291c7632a0ccd89d42179001d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/GlobalUsage
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to