r69430 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69429‎ | r69430 | r69431 >
Date:17:48, 16 July 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Refactor MessageGroups and add two cache clears
Modified paths:
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)
  • /trunk/extensions/Translate/tag/SpecialPageTranslationMovePage.php (modified) (history)
  • /trunk/extensions/Translate/tag/TranslatablePage.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageGroups.php
@@ -845,8 +845,7 @@
846846 global $wgAutoloadClasses;
847847
848848 $key = wfMemckey( 'translate-groups' );
849 - $cache = wfGetCache( CACHE_DB );
850 - $value = DependencyWrapper::getValueFromCache( $cache, $key );
 849+ $value = DependencyWrapper::getValueFromCache( self::getCache(), $key );
851850
852851 if ( $value === null ) {
853852 wfDebug( __METHOD__ . "-nocache\n" );
@@ -863,6 +862,24 @@
864863 }
865864 }
866865
 866+ /**
 867+ * Manually reset groups when dependencies cannot
 868+ * detect those automatically
 869+ */
 870+ public static function clearCache() {
 871+ $key = wfMemckey( 'translate-groups' );
 872+ self::getCache()->delete( $key );
 873+ }
 874+
 875+ /**
 876+ * Returns a cache object. Currently just wrapper for
 877+ * database cache, but could be improved or replaced
 878+ * with something that prefers Memcached over db.
 879+ */
 880+ protected static function getCache() {
 881+ return wfGetCache( CACHE_DB );
 882+ }
 883+
867884 public static function loadGroupDefinitions() {
868885 global $wgTranslateAddMWExtensionGroups;
869886 global $wgEnablePageTranslation, $wgTranslateGroupFiles;
@@ -924,7 +941,6 @@
925942 }
926943
927944 $key = wfMemckey( 'translate-groups' );
928 - $cache = wfGetCache( CACHE_DB );
929945 $value = array(
930946 'ac' => $wgTranslateAC,
931947 'ec' => $wgTranslateEC,
@@ -933,7 +949,7 @@
934950 );
935951
936952 $wrapper = new DependencyWrapper( $value, $deps );
937 - $wrapper->storeToCache( $cache, $key, 60*60*2 );
 953+ $wrapper->storeToCache( self::getCache(), $key, 60*60*2 );
938954
939955 wfDebug( __METHOD__ . "-end\n" );
940956 }
@@ -972,32 +988,34 @@
973989 }
974990 }
975991
976 - public $classes = array();
 992+ public $classes;
977993 private function __construct() {
978994 self::init();
979995
980 - global $wgTranslateEC, $wgTranslateCC;
981996
982 - $all = array_merge( $wgTranslateEC, array_keys( $wgTranslateCC ) );
983 - sort( $all );
984 -
985 - foreach ( $all as $id ) {
986 - $g = self::getGroup( $id );
987 - $this->classes[$g->getId()] = $g;
988 - }
989997 }
990998
991999 public static function singleton() {
9921000 static $instance;
993 -
9941001 if ( !$instance instanceof self ) {
9951002 $instance = new self();
9961003 }
997 -
9981004 return $instance;
9991005 }
10001006
10011007 public function getGroups() {
 1008+ if ( $this->classes === null ) {
 1009+ $this->classes = array();
 1010+ global $wgTranslateEC, $wgTranslateCC;
 1011+
 1012+ $all = array_merge( $wgTranslateEC, array_keys( $wgTranslateCC ) );
 1013+ sort( $all );
 1014+
 1015+ foreach ( $all as $id ) {
 1016+ $g = self::getGroup( $id );
 1017+ $this->classes[$g->getId()] = $g;
 1018+ }
 1019+ }
10021020 return $this->classes;
10031021 }
10041022 }
Index: trunk/extensions/Translate/tag/TranslatablePage.php
@@ -330,6 +330,7 @@
331331
332332 public function addMarkedTag( $revision, $value = null ) {
333333 $this->addTag( 'tp:mark', $revision, $value );
 334+ MessageGroups::clearCache();
334335 }
335336
336337 public function addReadyTag( $revision ) {
Index: trunk/extensions/Translate/tag/SpecialPageTranslationMovePage.php
@@ -341,6 +341,7 @@
342342 $newTpage->addMarkedTag( $this->newTitle->getLatestRevId( GAID_FOR_UPDATE ) );
343343 }
344344
 345+ MessageGroups::clearCache();
345346 //TODO: defer or make faster
346347 MessageIndexRebuilder::execute();
347348

Status & tagging log