r47309 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r47308‎ | r47309 | r47310 >
Date:08:11, 16 February 2009
Author:tstarling
Status:ok
Tags:
Comment:
Fix the cascade protection templatelinks update routine, which apparently has been broken since it was introduced, causing it to flood the job queue with refreshLinks job on every parser cache miss:
* Fixed incorrect interpretation of the result of $parserOutput->getTemplates() which led to the array_diff() always being non-empty
* No need to check for $db->select()===false, it throws an exception in that case
* Do a non-recursive update, no need to update links for other pages on a page view
Modified paths:
  • /trunk/phase3/includes/Article.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Article.php
@@ -3552,27 +3552,26 @@
35533553 __METHOD__ );
35543554
35553555 global $wgContLang;
3556 -
3557 - if( $res !== false ) {
3558 - foreach( $res as $row ) {
3559 - $tlTemplates[] = $wgContLang->getNsText( $row->tl_namespace ) . ':' . $row->tl_title ;
3560 - }
 3556+ foreach( $res as $row ) {
 3557+ $tlTemplates["{$row->tl_namespace}:{$row->tl_title}"] = true;
35613558 }
35623559
35633560 # Get templates from parser output.
3564 - $poTemplates_allns = $parserOutput->getTemplates();
3565 -
3566 - $poTemplates = array ();
3567 - foreach ( $poTemplates_allns as $ns_templates ) {
3568 - $poTemplates = array_merge( $poTemplates, $ns_templates );
 3561+ $poTemplates = array();
 3562+ foreach ( $parserOutput->getTemplates() as $ns => $templates ) {
 3563+ foreach ( $templates as $dbk => $id ) {
 3564+ $key = $row->tl_namespace . ':'. $row->tl_title;
 3565+ $poTemplates["$ns:$dbk"] = true;
 3566+ }
35693567 }
35703568
35713569 # Get the diff
3572 - $templates_diff = array_diff( $poTemplates, $tlTemplates );
 3570+ # Note that we simulate array_diff_key in PHP <5.0.x
 3571+ $templates_diff = array_diff_key( $poTemplates, $tlTemplates );
35733572
35743573 if( count( $templates_diff ) > 0 ) {
35753574 # Whee, link updates time.
3576 - $u = new LinksUpdate( $this->mTitle, $parserOutput );
 3575+ $u = new LinksUpdate( $this->mTitle, $parserOutput, false );
35773576 $u->doUpdate();
35783577 }
35793578 }

Status & tagging log