r69948 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69947‎ | r69948 | r69949 >
Date:15:01, 26 July 2010
Author:peter17
Status:ok
Tags:
Comment:
Retrieve subtemplates list only when retrieving template from API, not from cache (much faster when cache is enabled); fix some bugs
Modified paths:
  • /branches/iwtransclusion/phase3/includes/Interwiki.php (modified) (history)
  • /branches/iwtransclusion/phase3/includes/Revision.php (modified) (history)

Diff [purge]

Index: branches/iwtransclusion/phase3/includes/Interwiki.php
@@ -280,35 +280,11 @@
281281
282282 } else if( $transAPI !== '' ) {
283283
 284+ $interwiki = $title->getInterwiki( );
284285 $fullTitle = $title->getSemiPrefixedText( );
285286
286 - $finalText = self::fetchTemplateFromAPI( $wikiID, $transAPI, $fullTitle );
287 -
288 - //Retrieve the list of subtemplates
289 - $url2 = wfAppendQuery( $transAPI,
290 - array( 'action' => 'query',
291 - 'titles' => $fullTitle,
292 - 'prop' => 'templates',
293 - 'format' => 'json'
294 - )
295 - );
 287+ $finalText = self::fetchTemplateFromAPI( $interwiki, $transAPI, $fullTitle );
296288
297 - $get = Http::get( $url2 );
298 - $myArray = FormatJson::decode($get, true);
299 -
300 - // Here, we preload and cache the subtemplates
301 - if ( ! empty( $myArray['query'] )) {
302 - if ( ! empty( $myArray['query']['pages'] )) {
303 - $templates = array_pop( $myArray['query']['pages'] );
304 - if ( ! empty( $templates['templates'] )) {
305 - $templates = $templates['templates'];
306 - } else {
307 - $templates = array( );
308 - }
309 - self::cacheTemplatesFromAPI( $wikiID, $transAPI, $templates );
310 - }
311 - }
312 -
313289 return $finalText;
314290
315291 }
@@ -333,10 +309,10 @@
334310 /**
335311 * Retrieve the wikitext of a distant page using the API of the foreign wiki
336312 */
337 - public static function fetchTemplateFromAPI( $wikiID, $transAPI, $fullTitle ) {
 313+ public static function fetchTemplateFromAPI( $interwiki, $transAPI, $fullTitle ) {
338314 global $wgMemc, $wgTranscludeCacheExpiry;
339315
340 - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $fullTitle );
 316+ $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $fullTitle );
341317 $text = $wgMemc->get( $key );
342318 if( is_array ( $text ) &&
343319 isset ( $text['missing'] ) &&
@@ -365,6 +341,11 @@
366342 if ( $page && isset( $page['revisions'][0]['*'] ) ) {
367343 $text = $page['revisions'][0]['*'];
368344 $wgMemc->set( $key, $text, $wgTranscludeCacheExpiry );
 345+
 346+ // When we cache a template, we also retrieve and cache its subtemplates
 347+ $subtemplates = self::getSubtemplatesListFromAPI( $interwiki, $transAPI, $fullTitle );
 348+ self::cacheTemplatesFromAPI( $interwiki, $transAPI, $subtemplates );
 349+
369350 return $text;
370351 } else {
371352 $wgMemc->set( $key, array ( 'missing' => true ), $wgTranscludeCacheExpiry );
@@ -373,14 +354,38 @@
374355 return false;
375356 }
376357
377 - public static function cacheTemplatesFromAPI( $wikiID, $transAPI, $titles ){
 358+ public static function getSubtemplatesListFromAPI ( $interwiki, $transAPI, $title ) {
 359+ $url = wfAppendQuery( $transAPI,
 360+ array( 'action' => 'query',
 361+ 'titles' => $title,
 362+ 'prop' => 'templates',
 363+ 'format' => 'json'
 364+ )
 365+ );
 366+
 367+ $get = Http::get( $url );
 368+ $myArray = FormatJson::decode($get, true);
 369+
 370+ $templates = array( );
 371+ if ( ! empty( $myArray['query'] )) {
 372+ if ( ! empty( $myArray['query']['pages'] )) {
 373+ $templates = array_pop( $myArray['query']['pages'] );
 374+ if ( ! empty( $templates['templates'] )) {
 375+ $templates = $templates['templates'];
 376+ }
 377+ }
 378+ return $templates;
 379+ }
 380+ }
 381+
 382+ public static function cacheTemplatesFromAPI( $interwiki, $transAPI, $titles ){
378383 global $wgMemc, $wgTranscludeCacheExpiry;
379384
380385 $outdatedTitles = array( );
381386
382387 foreach( $titles as $title ){
383388 if ( isset ( $title['title'] ) ) {
384 - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $title['title'] );
 389+ $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $title['title'] );
385390 $text = $wgMemc->get( $key );
386391 if( !$text ){
387392 $outdatedTitles[] = $title['title'];
@@ -406,7 +411,7 @@
407412 if ( isset ( $content['query'] ) &&
408413 isset ( $content['query']['pages'] ) ) {
409414 foreach( $content['query']['pages'] as $page ) {
410 - $key = wfMemcKey( 'iwtransclustiontext', 'textid', $wikiID, $page['title'] );
 415+ $key = wfMemcKey( 'iwtransclustiontext', 'textid', $interwiki, $page['title'] );
411416 if ( isset ( $page['revisions'][0]['*'] ) ) {
412417 $text = $page['revisions'][0]['*'];
413418 } else {
Index: branches/iwtransclusion/phase3/includes/Revision.php
@@ -905,7 +905,7 @@
906906 // Caching may be beneficial for massive use of external storage
907907 global $wgRevisionCacheExpiry, $wgMemc;
908908 $textId = $this->getTextId();
909 - if( isset( $this->mWikiID ) ) {
 909+ if( isset( $this->mWikiID ) && $this->mWikiID !== false ) {
910910 $key = wfForeignMemcKey( $this->mWikiID, null, 'revisiontext', 'textid', $textId );
911911 } else {
912912 $key = wfMemcKey( 'revisiontext', 'textid', $textId );

Follow-up revisions

RevisionCommit summaryAuthorDate
r87107Merge r69853, r69948, r70411, r70575reedy00:31, 29 April 2011
r92988Merge r87107, Merge r69853, r69948, r70411, r70575reedy17:27, 24 July 2011

Status & tagging log