move store writing out of recache()
authorAntoine Musso <hashar@users.mediawiki.org>
Thu, 10 Nov 2011 11:56:52 +0000 (11:56 +0000)
committerAntoine Musso <hashar@users.mediawiki.org>
Thu, 10 Nov 2011 11:56:52 +0000 (11:56 +0000)
Writing to cache is now handled in a new method. That makes recache() a bit
shorter and easier to read. Since there is no point in writing data to
/dev/null , return early in such a case (ie if store is LCStore_Null).

includes/LocalisationCache.php

index ad707dc..ffea229 100644 (file)
@@ -710,6 +710,28 @@ class LocalisationCache {
                        $this->loadedItems[$code][$key] = true;
                }
 
+               # Write data to the persistant store
+               $this->saveLangInStore( $code, $data );
+
+               wfProfileOut( __METHOD__ );
+       }
+
+       /**
+        * Helper for recache() this is not mean to be called outside of recache()
+        * When the localisation store is null (LCStore_Null), method does nothing.
+        *
+        * @param $code String: language code to save data for
+        * @param $data Array: language data forged by recache()
+        */
+       protected function saveLangInStore( $code, $data ) {
+               wfProfileIn( __METHOD__ );
+
+               if( $this->store instanceof LCStore_Null ) {
+                       # No point in saving data to /dev/null
+                       wfProfileOut( __METHOD__ );
+                       return;
+               }
+       
                # Save to the persistent cache
                $this->store->startWrite( $code );
                foreach ( $allData as $key => $value ) {
@@ -724,11 +746,7 @@ class LocalisationCache {
                $this->store->finishWrite();
 
                # Clear out the MessageBlobStore
-               # HACK: If using a null (i.e. disabled) storage backend, we
-               # can't write to the MessageBlobStore either
-               if ( !$this->store instanceof LCStore_Null ) {
-                       MessageBlobStore::clear();
-               }
+               MessageBlobStore::clear();
 
                wfProfileOut( __METHOD__ );
        }
@@ -1186,4 +1204,4 @@ class LocalisationCache_BulkLoad extends LocalisationCache {
                        $this->unload( $code );
                }
        }
-}
\ No newline at end of file
+}