https://www.mediawiki.org/wiki/Special:Code/MediaWiki/101993

Revision: 101993
Author:   nikerabbit
Date:     2011-11-04 14:28:05 +0000 (Fri, 04 Nov 2011)
Log Message:
-----------
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: trunk/extensions/Translate/utils/MessageIndex.php
===================================================================
--- trunk/extensions/Translate/utils/MessageIndex.php   2011-11-04 14:19:52 UTC 
(rev 101992)
+++ trunk/extensions/Translate/utils/MessageIndex.php   2011-11-04 14:28:05 UTC 
(rev 101993)
@@ -40,11 +40,14 @@
        abstract public function retrieve();
        abstract protected function store( array $array );
 
-       public function rebuild() {
+       public function rebuild( /*bool*/ $scratch = false ) {
                $groups = MessageGroups::singleton()->getGroups();
 
-               $old = $this->retrieve();
-               $new = array();
+               $new = $old = array();
+               if ( !$scratch ) {
+                       // To avoid inifinite recursion
+                       $old = $this->retrieve();
+               }
                $postponed = array();
 
                STDOUT( "Working with ", 'main' );
@@ -69,6 +72,7 @@
 
                $this->store( $new );
                $this->clearMessageGroupStats( $old, $new );
+               return $new;
        }
 
        /**
@@ -165,7 +169,7 @@
                if ( file_exists( $file ) ) {
                        return $this->index = unserialize( file_get_contents( 
$file ) );
                } else {
-                       return $this->index = array();
+                       return $this->index = $this->rebuild( 'empty' );
                }
        }
 
@@ -198,7 +202,7 @@
                if ( is_array( $data ) ) {
                        return $this->index = $data;
                } else {
-                       return $this->index = array();
+                       return $this->index = $this->rebuild( 'empty' );
                }
        }
 


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to