From 3d8479f993314ee162cdfb64ae84834358c15bca Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 5 Mar 2007 11:55:29 +0000 Subject: [PATCH] Use a separate connection for commons DB --- includes/Image.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/includes/Image.php b/includes/Image.php index 9145a0dcf6..d56a1ddbf9 100644 --- a/includes/Image.php +++ b/includes/Image.php @@ -347,7 +347,7 @@ class Image # capitalize the first letter of the filename before # looking it up in the shared repository. $name = $wgContLang->ucfirst($this->name); - $dbc = wfGetDB( DB_SLAVE, 'commons' ); + $dbc = Image::getCommonsDB(); $row = $dbc->selectRow( "`$wgSharedUploadDBname`.{$wgSharedUploadDBprefix}image", array( @@ -449,8 +449,7 @@ class Image // Write to the other DB using selectDB, not database selectors // This avoids breaking replication in MySQL - $dbw = wfGetDB( DB_MASTER, 'commons' ); - $dbw->selectDB( $wgSharedUploadDBname ); + $dbw = Image::getCommonsDB(); } else { $dbw = wfGetDB( DB_MASTER ); } @@ -2329,6 +2328,18 @@ class Image } } + static function getCommonsDB() { + static $dbc; + global $wgLoadBalancer; + if ( !isset( $dbc ) ) { + $i = $wgLoadBalancer->getGroupIndex( 'commons' ); + $dbinfo = $wgLoadBalancer->mServers[$i]; + $dbc = new Database( $dbinfo['host'], $dbinfo['user'], + $dbinfo['password'], $wgSharedUploadDBname ); + } + return $dbc; + } + } //class /** -- 2.20.1