r24713 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24712‎ | r24713 | r24714 >
Date:22:01, 9 August 2007
Author:daniel
Status:old
Tags:
Comment:
cache parsed gadget list using wgMemc
Modified paths:
  • /trunk/extensions/Gadgets/Gadgets.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Gadgets/Gadgets.php
@@ -28,11 +28,24 @@
2929 $wgHooks['RenderPreferencesForm'][] = 'wfGadgetsRenderPreferencesForm';
3030 $wgHooks['ResetPreferences'][] = 'wfGadgetsResetPreferences';
3131 $wgHooks['BeforePageDisplay'][] = 'wfGadgetsBeforePageDisplay';
 32+$wgHooks['ArticleSave'][] = 'wfGadgetsArticleSave';
3233 $wgHooks['LoadAllMessages'][] = "loadGadgetsI18n";
3334
3435 $wgAutoloadClasses['SpecialGadgets'] = dirname( __FILE__ ) . '/SpecialGadgets.php';
3536 $wgSpecialPages['Gadgets'] = 'SpecialGadgets';
3637
 38+function wfGadgetsArticleSave( &$article ) {
 39+ //purge from cache if need be
 40+ $title =& $article->mTitle;
 41+ if( $title->getNamespace() == NS_MEDIAWIKI && $title->getText() == 'Gadgets-definition' ) {
 42+ global $wgMemc, $wgDBname;
 43+ $key = "$wgDBname:gadgets-definition";
 44+ $wgMemc->delete( $key );
 45+ wfDebug("wfGadgetsArticleSave: MediaWiki:Gadgets-definition edited, cache entry $key purged\n");
 46+ }
 47+ return true;
 48+}
 49+
3750 function wfLoadGadgets() {
3851 static $gadgets = NULL;
3952
@@ -54,9 +67,15 @@
5568
5669 function wfLoadGadgetsStructured() {
5770 global $wgContLang, $wgCapitalLinks;
 71+ global $wgMemc, $wgDBname;
5872
5973 static $gadgets = NULL;
 74+ if ( $gadgets !== NULL ) return $gadgets;
6075
 76+ $key = "$wgDBname:gadgets-definition";
 77+
 78+ //cached?
 79+ $gadgets = $wgMemc->get( $key );
6180 if ( $gadgets !== NULL ) return $gadgets;
6281
6382 $g = wfMsgForContentNoTrans( "Gadgets-definition" );
@@ -91,6 +110,10 @@
92111 }
93112 }
94113
 114+ //cache for a while. gets purged automatically when MediaWiki:Gadgets-definition is edited
 115+ $wgMemc->set( $key, $gadgets, 900 );
 116+ wfDebug("wfLoadGadgetsStructured: MediaWiki:Gadgets-definition parsed, cache entry $key updated\n");
 117+
95118 return $gadgets;
96119 }
97120

Status & tagging log