r69421 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69420‎ | r69421 | r69422 >
Date:11:40, 16 July 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Cache loaded message groups with help of DependencyWrapper
Modified paths:
  • /trunk/extensions/Translate/MessageGroups.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/MessageGroups.php
@@ -827,27 +827,62 @@
828828
829829 return $checker;
830830 }
 831+
 832+ public function getDescription() {
 833+ $title = $this->title;
 834+ $target = SpecialPage::getTitleFor( 'MyLanguage', $title )->getPrefixedText();
 835+ return wfMsgNoTrans( 'translate-tag-page-desc', $title, $target );
 836+ }
831837 }
832838
833839 class MessageGroups {
834840 public static function init() {
835841 static $loaded = false;
 842+ if ( $loaded ) return;
 843+ $loaded = true;
836844
837 - if ( $loaded ) {
838 - return;
 845+ global $wgTranslateCC, $wgTranslateEC, $wgTranslateAC;
 846+ global $wgAutoloadClasses;
 847+
 848+ $key = wfMemckey( 'translate-groups' );
 849+ $cache = wfGetCache( CACHE_DB );
 850+ $value = DependencyWrapper::getValueFromCache( $cache, $key );
 851+
 852+ if ( $value === null ) {
 853+ wfDebug( __METHOD__ . "-nocache\n" );
 854+ self::loadGroupDefinitions();
 855+ } else {
 856+ wfDebug( __METHOD__ . "-withcache\n" );
 857+ $wgTranslateCC = $value['cc'];
 858+ $wgTranslateAC = $value['ac'];
 859+ $wgTranslateEC = $value['ec'];
 860+
 861+ foreach ( $value['autoload'] as $class => $file ) {
 862+ $wgAutoloadClasses[$class] = $file;
 863+ }
839864 }
840 - wfDebug( __METHOD__ . "\n" );
 865+ }
841866
 867+ public static function loadGroupDefinitions() {
842868 global $wgTranslateAddMWExtensionGroups;
 869+ global $wgEnablePageTranslation, $wgTranslateGroupFiles;
 870+ global $wgTranslateAC, $wgTranslateEC, $wgTranslateCC;
 871+ global $wgAutoloadClasses;
843872
 873+ $deps = array();
 874+ $deps[] = new GlobalDependency( 'wgTranslateAddMWExtensionGroups' );
 875+ $deps[] = new GlobalDependency( 'wgEnablePageTranslation' );
 876+ $deps[] = new GlobalDependency( 'wgTranslateGroupFiles' );
 877+ $deps[] = new GlobalDependency( 'wgTranslateAC' );
 878+ $deps[] = new GlobalDependency( 'wgTranslateEC' );
 879+ $deps[] = new GlobalDependency( 'wgTranslateCC' );
 880+ $deps[] = New FileDependency( dirname( __FILE__ ) . '/groups/mediawiki-defines.txt' );
 881+
844882 if ( $wgTranslateAddMWExtensionGroups ) {
845883 $a = new PremadeMediawikiExtensionGroups;
846884 $a->addAll();
847885 }
848886
849 - global $wgTranslateCC;
850 - global $wgEnablePageTranslation;
851 -
852887 if ( $wgEnablePageTranslation ) {
853888 $dbr = wfGetDB( DB_SLAVE );
854889
@@ -862,24 +897,25 @@
863898 $id = "page|$title";
864899 $wgTranslateCC[$id] = new WikiPageMessageGroup( $id, $title );
865900 $wgTranslateCC[$id]->setLabel( $title );
866 - $target = SpecialPage::getTitleFor( 'MyLanguage', $title )->getPrefixedText();
867 - $wgTranslateCC[$id]->setDescription( wfMsgNoTrans( 'translate-tag-page-desc', $title, $target ) );
868901 }
869902 }
870903
871904 wfRunHooks( 'TranslatePostInitGroups', array( &$wgTranslateCC ) );
872905
873 - global $wgTranslateGroupFiles, $wgAutoloadClasses;
 906+ $autoload = array();
874907
875908 foreach ( $wgTranslateGroupFiles as $configFile ) {
876909 wfDebug( $configFile . "\n" );
 910+ $deps[] = new FileDependency( realpath( $configFile ) );
877911 $fgroups = TranslateYaml::parseGroupFile( $configFile );
878912
879913 foreach( $fgroups as $id => $conf ) {
880914 if ( !empty( $conf['AUTOLOAD'] ) && is_array( $conf['AUTOLOAD'] ) ) {
881915 $dir = dirname( $configFile );
882916 foreach ( $conf['AUTOLOAD'] as $class => $file ) {
 917+ // For this request and for caching
883918 $wgAutoloadClasses[$class] = "$dir/$file";
 919+ $autoload[$class] = "$dir/$file";
884920 }
885921 }
886922 $group = MessageGroupBase::factory( $conf );
@@ -887,7 +923,19 @@
888924 }
889925 }
890926
891 - $loaded = true;
 927+ $key = wfMemckey( 'translate-groups' );
 928+ $cache = wfGetCache( CACHE_DB );
 929+ $value = array(
 930+ 'ac' => $wgTranslateAC,
 931+ 'ec' => $wgTranslateEC,
 932+ 'cc' => $wgTranslateCC,
 933+ 'autoload' => $autoload,
 934+ );
 935+
 936+ $wrapper = new DependencyWrapper( $value, $deps );
 937+ $wrapper->storeToCache( $cache, $key, 60*60*2 );
 938+
 939+ wfDebug( __METHOD__ . "-end\n" );
892940 }
893941
894942 public static function getGroup( $id ) {

Status & tagging log