Aaron Schulz has uploaded a new change for review.

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

Change subject: Defer copyLocalImagelinks() logic to avoid DB contention
......................................................................

Defer copyLocalImagelinks() logic to avoid DB contention

Run the updates in autocommit mode after the main transaction.
Files are already moved at this point, so we are committed to
moving forward.

Bug: T139306
Change-Id: I1392db0a764d6c8d9f98a73004cf2a808f502384
---
M GlobalUsage_body.php
1 file changed, 31 insertions(+), 20 deletions(-)


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

diff --git a/GlobalUsage_body.php b/GlobalUsage_body.php
index 7713230..b02c184 100644
--- a/GlobalUsage_body.php
+++ b/GlobalUsage_body.php
@@ -101,28 +101,39 @@
         *
         * @param $title Title Title of the file to copy entries from.
         */
-       public function copyLocalImagelinks( $title ) {
-               global $wgContLang;
+       public function copyLocalImagelinks( Title $title ) {
+               DeferredUpdates::addCallableUpdate( function () use ( $title ) {
+                       global $wgContLang;
 
-               $dbr = wfGetDB( DB_SLAVE );
-               $res = $dbr->select(
-                       array( 'imagelinks', 'page' ),
-                       array( 'il_to', 'page_id', 'page_namespace', 
'page_title' ),
-                       array( 'il_from = page_id', 'il_to' => 
$title->getDBkey() ),
-                       __METHOD__
-               );
-               $insert = array();
-               foreach ( $res as $row ) {
-                       $insert[] = array(
-                               'gil_wiki' => $this->interwiki,
-                               'gil_page' => $row->page_id,
-                               'gil_page_namespace_id' => $row->page_namespace,
-                               'gil_page_namespace' => $wgContLang->getNsText( 
$row->page_namespace ),
-                               'gil_page_title' => $row->page_title,
-                               'gil_to' => $row->il_to,
+                       $repo = RepoGroup::singleton()->getLocalRepo();
+                       $file = $repo->newFile( $title );
+                       $file->load( File::READ_LATEST );
+                       if ( $file->exists() ) {
+                               return; // sanity; file exists again
+                       }
+
+                       $dbw = wfGetDB( DB_MASTER );
+                       $res = $dbw->select(
+                               array( 'imagelinks', 'page' ),
+                               array( 'il_to', 'page_id', 'page_namespace', 
'page_title' ),
+                               array( 'il_from = page_id', 'il_to' => 
$title->getDBkey() ),
+                               __METHOD__
                        );
-               }
-               $this->db->insert( 'globalimagelinks', $insert, __METHOD__, 
array( 'IGNORE' ) );
+
+                       $insert = array();
+                       foreach ( $res as $row ) {
+                               $insert[] = array(
+                                       'gil_wiki' => $this->interwiki,
+                                       'gil_page' => $row->page_id,
+                                       'gil_page_namespace_id' => 
$row->page_namespace,
+                                       'gil_page_namespace' => 
$wgContLang->getNsText( $row->page_namespace ),
+                                       'gil_page_title' => $row->page_title,
+                                       'gil_to' => $row->il_to,
+                               );
+                       }
+
+                       $this->db->insert( 'globalimagelinks', $insert, 
__METHOD__, array( 'IGNORE' ) );
+               } );
        }
 
        /**

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1392db0a764d6c8d9f98a73004cf2a808f502384
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