r69874 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69873‎ | r69874 | r69875 >
Date:16:53, 25 July 2010
Author:philip
Status:ok
Tags:
Comment:
Performance improvement: in doVariants(), concatenate a bulk of titles to a single string, thus we just need to call convertLinkToAllVariants() once.
Modified paths:
  • /trunk/phase3/includes/parser/LinkHolderArray.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/parser/LinkHolderArray.php
@@ -296,37 +296,57 @@
297297 $linkCache = LinkCache::singleton();
298298 $sk = $this->parent->getOptions()->getSkin();
299299 $threshold = $this->getStubThreshold();
300 -
301 - // Add variants of links to link batch
 300+ $titlesToBeConverted = '';
 301+ $titlesAttrs = array();
 302+
 303+ // Concatenate titles to a single string, thus we only need auto convert the
 304+ // single string to all variants. This would improve parser's performance
 305+ // significantly.
302306 foreach ( $this->internals as $ns => $entries ) {
303307 foreach ( $entries as $index => $entry ) {
304 - $key = "$ns:$index";
305308 $pdbk = $entry['pdbk'];
306 - $title = $entry['title'];
307 - $titleText = $title->getText();
308 -
309 - // generate all variants of the link title text
310 - $allTextVariants = $wgContLang->convertLinkToAllVariants($titleText);
311 -
312 - // if link was not found (in first query), add all variants to query
313 - if ( !isset($colours[$pdbk]) ){
314 - foreach($allTextVariants as $textVariant){
315 - if($textVariant != $titleText){
316 - $variantTitle = Title::makeTitle( $ns, $textVariant );
317 - if(is_null($variantTitle)) continue;
318 - $linkBatch->addObj( $variantTitle );
319 - $variantMap[$variantTitle->getPrefixedDBkey()][] = $key;
320 - }
321 - }
 309+ // we only deal with new links (in its first query)
 310+ if ( !isset( $colours[$pdbk] ) ) {
 311+ $title = $entry['title'];
 312+ $titleText = $title->getText();
 313+ $titlesAttrs[] = array(
 314+ 'ns' => $ns,
 315+ 'key' => "$ns:$index",
 316+ 'titleText' => $titleText,
 317+ );
 318+ // separate titles with \0 because it would never appears
 319+ // in a valid title
 320+ $titlesToBeConverted .= $title . '\0';
322321 }
323322 }
324323 }
 324+
 325+ // Now do the conversion and explode string to text of titles
 326+ $titlesAllVariants = $wgContLang->convertLinkToAllVariants( $titlesToBeConverted );
 327+ $allVariantsName = array_keys( $titlesAllVariants );
 328+ foreach ( $titlesAllVariants as &$titlesVariant ) {
 329+ $titlesVariant = explode( '\0', $titlesVariant );
 330+ }
 331+
 332+ // Then add variants of links to link batch
 333+ for ( $i = 0; $l = count( $titlesAttrs ), $i < $l; $i ++ ) {
 334+ foreach ( $allVariantsName as $variantName ) {
 335+ $textVariant = $titlesAllVariants[$variantName][$i];
 336+ extract( $titlesAttrs[$i] );
 337+ if($textVariant != $titleText){
 338+ $variantTitle = Title::makeTitle( $ns, $textVariant );
 339+ if( is_null( $variantTitle ) ) { continue; }
 340+ $linkBatch->addObj( $variantTitle );
 341+ $variantMap[$variantTitle->getPrefixedDBkey()][] = $key;
 342+ }
 343+ }
 344+ }
325345
326346 // process categories, check if a category exists in some variant
327347 $categoryMap = array(); // maps $category_variant => $category (dbkeys)
328348 $varCategories = array(); // category replacements oldDBkey => newDBkey
329349 foreach( $output->getCategoryLinks() as $category ){
330 - $variants = $wgContLang->convertLinkToAllVariants($category);
 350+ $variants = $wgContLang->convertLinkToAllVariants( $category );
331351 foreach($variants as $variant){
332352 if($variant != $category){
333353 $variantTitle = Title::newFromDBkey( Title::makeName(NS_CATEGORY,$variant) );

Follow-up revisions

RevisionCommit summaryAuthorDate
r69875follow up r69874. use string instead of object .philip16:59, 25 July 2010
r69949Follow up r69874. Fix the separation markup.philip16:09, 26 July 2010

Status & tagging log