From: Tim Starling Date: Mon, 5 Mar 2007 11:55:29 +0000 (+0000) Subject: Use a separate connection for commons DB X-Git-Tag: 1.31.0-rc.0~53913 X-Git-Url: http://git.cyclocoop.org//%22javascript:ModifierStyle%28%27%22.%24id.%22%27%29/%22?a=commitdiff_plain;h=3d8479f993314ee162cdfb64ae84834358c15bca;p=lhc%2Fweb%2Fwiklou.git Use a separate connection for commons DB --- 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 /**