From 50a581996a84639d2b296b3b5cc0682677519163 Mon Sep 17 00:00:00 2001 From: Victor Vasiliev Date: Sat, 10 May 2008 19:22:14 +0000 Subject: [PATCH] * Fix image redirect caching so it doesn't break image redirects on shared repositories --- includes/Database.php | 8 ++++++++ includes/GlobalFunctions.php | 21 ++++++++++----------- includes/filerepo/LocalFile.php | 2 +- includes/filerepo/LocalRepo.php | 8 ++++++-- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/includes/Database.php b/includes/Database.php index 001b0448c8..9efc395965 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -226,6 +226,14 @@ class Database { return $this->$name; } + function getWikiID() { + if( $this->mTablePrefix ) { + return "{$this->mDBname}-{$this->mTablePrefix}"; + } else { + return $this->mDBname; + } + } + #------------------------------------------------------------------------------ # Other functions #------------------------------------------------------------------------------ diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index e84e82cbf0..8aac928c23 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2337,13 +2337,8 @@ function wfFormatStackFrame($frame) { * Get a cache key */ function wfMemcKey( /*... */ ) { - global $wgDBprefix, $wgDBname; $args = func_get_args(); - if ( $wgDBprefix ) { - $key = "$wgDBname-$wgDBprefix:" . implode( ':', $args ); - } else { - $key = $wgDBname . ':' . implode( ':', $args ); - } + $key = wfWikiID() . ':' . implode( ':', $args ); return $key; } @@ -2364,12 +2359,16 @@ function wfForeignMemcKey( $db, $prefix /*, ... */ ) { * Get an ASCII string identifying this wiki * This is used as a prefix in memcached keys */ -function wfWikiID() { - global $wgDBprefix, $wgDBname; - if ( $wgDBprefix ) { - return "$wgDBname-$wgDBprefix"; +function wfWikiID( $db = null ) { + if( $db instanceof Database ) { + return $db->getWikiID(); } else { - return $wgDBname; + global $wgDBprefix, $wgDBname; + if ( $wgDBprefix ) { + return "$wgDBname-$wgDBprefix"; + } else { + return $wgDBname; + } } } diff --git a/includes/filerepo/LocalFile.php b/includes/filerepo/LocalFile.php index 29a638932f..1f1c84d3df 100644 --- a/includes/filerepo/LocalFile.php +++ b/includes/filerepo/LocalFile.php @@ -5,7 +5,7 @@ /** * Bump this number when serialized cache records may be incompatible. */ -define( 'MW_FILE_VERSION', 7 ); +define( 'MW_FILE_VERSION', 8 ); /** * Class to represent a local file in the wiki's own database diff --git a/includes/filerepo/LocalRepo.php b/includes/filerepo/LocalRepo.php index 1e08268402..e123a52f3a 100644 --- a/includes/filerepo/LocalRepo.php +++ b/includes/filerepo/LocalRepo.php @@ -15,6 +15,10 @@ class LocalRepo extends FSRepo { return wfGetDB( DB_MASTER ); } + function getMemcKey( $key ) { + return wfWikiID( $this->getSlaveDB() ) . ":{$key}"; + } + function newFileFromRow( $row ) { if ( isset( $row->img_name ) ) { return LocalFile::newFromRow( $row, $this ); @@ -104,7 +108,7 @@ class LocalRepo extends FSRepo { $title = Title::makeTitle( NS_IMAGE, $title->getText() ); } - $memcKey = wfMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) ); + $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) ); $cachedValue = $wgMemc->get( $memcKey ); if( $cachedValue ) { return Title::newFromDbKey( $cachedValue ); @@ -135,7 +139,7 @@ class LocalRepo extends FSRepo { function invalidateImageRedirect( $title ) { global $wgMemc; - $memcKey = wfMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) ); + $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) ); $wgMemc->delete( $memcKey ); } } -- 2.20.1