r96852 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96851‎ | r96852 | r96853 >
Date:15:17, 12 September 2011
Author:catrope
Status:ok (Comments)
Tags:
Comment:
RL2: Followup r96837: fix ugliness in dealing with ForeignDBRepo names caching mentioned in the commit summary of r96837
Modified paths:
  • /branches/RL2/extensions/Gadgets/backend/ForeignDBGadgetRepo.php (modified) (history)
  • /branches/RL2/extensions/Gadgets/backend/LocalGadgetRepo.php (modified) (history)

Diff [purge]

Index: branches/RL2/extensions/Gadgets/backend/LocalGadgetRepo.php
@@ -8,6 +8,9 @@
99 protected $data = array();
1010 protected $namesLoaded = false;
1111
 12+ /** Memcached key of the gadget names list. Subclasses may override this in their constructor */
 13+ protected $namesKey;
 14+
1215 /*** Public methods inherited from GadgetRepo ***/
1316
1417 /**
@@ -19,6 +22,8 @@
2023
2124 // TODO: define options
2225 // FIXME if there are none, drop the mandatory param
 26+
 27+ $this->namesKey = $this->getMemcKey( 'gadgets', 'localreponames' );
2328 }
2429
2530 public function getGadgetIds() {
@@ -99,9 +104,8 @@
100105 $wgMemc->set( $key, $this->data[$id] );
101106 }
102107 // Clear the gadget names array in memc
103 - $namesKey = $this->getMemcKey( 'gadgets', 'localreponames' );
104 - if ( $namesKey !== false ) {
105 - $wgMemc->delete( $namesKey );
 108+ if ( $this->namesKey !== false ) {
 109+ $wgMemc->delete( $this->namesKey );
106110 }
107111
108112 return Status::newGood();
@@ -126,9 +130,8 @@
127131 $wgMemc->delete( $key );
128132 }
129133 // Clear the gadget names array in memc
130 - $namesKey = $this->getMemcKey( 'gadgets', 'localreponames' );
131 - if ( $namesKey !== false ) {
132 - $wgMemc->delete( $namesKey );
 134+ if ( $this->namesKey !== false ) {
 135+ $wgMemc->delete( $this->namesKey );
133136 }
134137
135138 if ( $affectedRows === 0 ) {
@@ -180,8 +183,7 @@
181184 }
182185
183186 // Try memc
184 - $key = $this->getMemcKey( 'gadgets', 'localreponames' );
185 - $cached = $key !== false ? $wgMemc->get( $key ) : false;
 187+ $cached = $this->namesKey !== false ? $wgMemc->get( $this->namesKey ) : false;
186188 if ( is_array( $cached ) ) {
187189 // Yay, data is in cache
188190 // Add to $this->data , but let things already in $this->data take precedence
Index: branches/RL2/extensions/Gadgets/backend/ForeignDBGadgetRepo.php
@@ -25,6 +25,8 @@
2626 public function __construct( array $options ) {
2727 parent::__construct( $options );
2828
 29+ $this->namesKey = $this->getMemcKey( 'gadgets', 'foreigndbreponames' );
 30+
2931 $optionKeys = array( 'source', 'dbType', 'dbServer', 'dbUser', 'dbPassword', 'dbName',
3032 'dbFlags', 'tablePrefix', 'hasSharedCache' );
3133 foreach ( $optionKeys as $optionKey ) {
@@ -64,11 +66,6 @@
6567 protected function getMemcKey( /* ... */ ) {
6668 if ( $this->hasSharedCache ) {
6769 $args = func_get_args();
68 - // FIXME: This is a dirty hack. Need to cache localrepo and foreignrepo name lists separately
69 - // because one includes non-shared gadgets and the other doesn't
70 - if ( $args[1] === 'localreponames' ) {
71 - $args[1] = 'foreignreponames';
72 - }
7370 array_unshift( $args, $this->dbName, $this->tablePrefix );
7471 return call_user_func_array( 'wfForeignMemcKey', $args );
7572 } else {

Follow-up revisions

RevisionCommit summaryAuthorDate
r96868RL2: Fix breakage in r96852: can't use getMemcKey() in the constructor when $...catrope17:12, 12 September 2011
r96869RL2: Another fix for r96852, forgot to swap out a variablecatrope17:18, 12 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r96837RL2: Reorganize caching in LocalGadgetRepo so we no longer load the entire ga...catrope13:38, 12 September 2011

Comments

#Comment by Krinkle (talk | contribs)   17:50, 12 September 2011

Nice!

Status & tagging log