r101993 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101992‎ | r101993 | r101994 >
Date:14:28, 4 November 2011
Author:nikerabbit
Status:ok
Tags:
Comment:
Made MessageIndex cache a bit more robust:
If the cache doesn't exist (perhaps it was evicted from almost full memcached or accelerator), create it.
This also means that full message group cache will be cleared, which might be a bit inefficient - but on the other hand it shouldn't be a big deal on small sites, where this scenario is most likely due improper configuration.
Now it also works if the cache is fully broken and doesn't hold items even during the request, because the process cache is populated directly without roundtrip form the caching layer.
Modified paths:
  • /trunk/extensions/Translate/utils/MessageIndex.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/MessageIndex.php
@@ -40,11 +40,14 @@
4141 abstract public function retrieve();
4242 abstract protected function store( array $array );
4343
44 - public function rebuild() {
 44+ public function rebuild( /*bool*/ $scratch = false ) {
4545 $groups = MessageGroups::singleton()->getGroups();
4646
47 - $old = $this->retrieve();
48 - $new = array();
 47+ $new = $old = array();
 48+ if ( !$scratch ) {
 49+ // To avoid inifinite recursion
 50+ $old = $this->retrieve();
 51+ }
4952 $postponed = array();
5053
5154 STDOUT( "Working with ", 'main' );
@@ -69,6 +72,7 @@
7073
7174 $this->store( $new );
7275 $this->clearMessageGroupStats( $old, $new );
 76+ return $new;
7377 }
7478
7579 /**
@@ -165,7 +169,7 @@
166170 if ( file_exists( $file ) ) {
167171 return $this->index = unserialize( file_get_contents( $file ) );
168172 } else {
169 - return $this->index = array();
 173+ return $this->index = $this->rebuild( 'empty' );
170174 }
171175 }
172176
@@ -198,7 +202,7 @@
199203 if ( is_array( $data ) ) {
200204 return $this->index = $data;
201205 } else {
202 - return $this->index = array();
 206+ return $this->index = $this->rebuild( 'empty' );
203207 }
204208 }
205209

Status & tagging log