r34595 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34594‎ | r34595 | r34596 >
Date:19:22, 10 May 2008
Author:vasilievvv
Status:old
Tags:
Comment:
* Fix image redirect caching so it doesn't break image redirects on shared repositories
Modified paths:
  • /trunk/phase3/includes/Database.php (modified) (history)
  • /trunk/phase3/includes/GlobalFunctions.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalFile.php (modified) (history)
  • /trunk/phase3/includes/filerepo/LocalRepo.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/GlobalFunctions.php
@@ -2337,13 +2337,8 @@
23382338 * Get a cache key
23392339 */
23402340 function wfMemcKey( /*... */ ) {
2341 - global $wgDBprefix, $wgDBname;
23422341 $args = func_get_args();
2343 - if ( $wgDBprefix ) {
2344 - $key = "$wgDBname-$wgDBprefix:" . implode( ':', $args );
2345 - } else {
2346 - $key = $wgDBname . ':' . implode( ':', $args );
2347 - }
 2342+ $key = wfWikiID() . ':' . implode( ':', $args );
23482343 return $key;
23492344 }
23502345
@@ -2364,12 +2359,16 @@
23652360 * Get an ASCII string identifying this wiki
23662361 * This is used as a prefix in memcached keys
23672362 */
2368 -function wfWikiID() {
2369 - global $wgDBprefix, $wgDBname;
2370 - if ( $wgDBprefix ) {
2371 - return "$wgDBname-$wgDBprefix";
 2363+function wfWikiID( $db = null ) {
 2364+ if( $db instanceof Database ) {
 2365+ return $db->getWikiID();
23722366 } else {
2373 - return $wgDBname;
 2367+ global $wgDBprefix, $wgDBname;
 2368+ if ( $wgDBprefix ) {
 2369+ return "$wgDBname-$wgDBprefix";
 2370+ } else {
 2371+ return $wgDBname;
 2372+ }
23742373 }
23752374 }
23762375
Index: trunk/phase3/includes/filerepo/LocalFile.php
@@ -5,7 +5,7 @@
66 /**
77 * Bump this number when serialized cache records may be incompatible.
88 */
9 -define( 'MW_FILE_VERSION', 7 );
 9+define( 'MW_FILE_VERSION', 8 );
1010
1111 /**
1212 * Class to represent a local file in the wiki's own database
Index: trunk/phase3/includes/filerepo/LocalRepo.php
@@ -15,6 +15,10 @@
1616 return wfGetDB( DB_MASTER );
1717 }
1818
 19+ function getMemcKey( $key ) {
 20+ return wfWikiID( $this->getSlaveDB() ) . ":{$key}";
 21+ }
 22+
1923 function newFileFromRow( $row ) {
2024 if ( isset( $row->img_name ) ) {
2125 return LocalFile::newFromRow( $row, $this );
@@ -104,7 +108,7 @@
105109 $title = Title::makeTitle( NS_IMAGE, $title->getText() );
106110 }
107111
108 - $memcKey = wfMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
 112+ $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
109113 $cachedValue = $wgMemc->get( $memcKey );
110114 if( $cachedValue ) {
111115 return Title::newFromDbKey( $cachedValue );
@@ -135,7 +139,7 @@
136140
137141 function invalidateImageRedirect( $title ) {
138142 global $wgMemc;
139 - $memcKey = wfMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
 143+ $memcKey = $this->getMemcKey( "image_redirect:" . md5( $title->getPrefixedDBkey() ) );
140144 $wgMemc->delete( $memcKey );
141145 }
142146 }
Index: trunk/phase3/includes/Database.php
@@ -226,6 +226,14 @@
227227 return $this->$name;
228228 }
229229
 230+ function getWikiID() {
 231+ if( $this->mTablePrefix ) {
 232+ return "{$this->mDBname}-{$this->mTablePrefix}";
 233+ } else {
 234+ return $this->mDBname;
 235+ }
 236+ }
 237+
230238 #------------------------------------------------------------------------------
231239 # Other functions
232240 #------------------------------------------------------------------------------

Status & tagging log