r68483 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68482‎ | r68483 | r68484 >
Date:19:45, 23 June 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Support meta groups and increase performance with namespace filtering in sql
Modified paths:
  • /trunk/extensions/Translate/SpecialTranslationStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/SpecialTranslationStats.php
@@ -44,7 +44,6 @@
4545 if ( $t === 'group' ) {
4646 $values = preg_replace( '~^page_~', 'page|', $values );
4747 }
48 - //var_dump( implode( ',', $values ) );
4948 $opts[$t] = implode( ',', $values );
5049 }
5150
@@ -301,11 +300,13 @@
302301 foreach ( $res as $row ) {
303302 $date = $wgLang->sprintfDate( $dateFormat, $row->rc_timestamp );
304303
305 - $index = $so->indexOf( $row );
306 - if ( $index < 0 ) continue;
 304+ $indexes = $so->indexOf( $row );
 305+ if ( $indexes === -1 ) continue;
307306
308 - if ( !isset( $data[$date][$index] ) ) $data[$date][$index] = 0;
309 - $data[$date][$index]++;
 307+ foreach ( (array) $indexes as $index ) {
 308+ if ( !isset( $data[$date][$index] ) ) $data[$date][$index] = 0;
 309+ $data[$date][$index]++;
 310+ }
310311 }
311312
312313 $labels = null;
@@ -389,13 +390,18 @@
390391 public function preQuery( &$tables, &$fields, &$conds, &$type, &$options ) {
391392 $db = wfGetDB( DB_SLAVE );
392393
393 - $groups = explode( ',', $this->opts['group'] );
394 - $codes = explode( ',', $this->opts['language'] );
 394+ $groups = array_map( 'trim', explode( ',', $this->opts['group'] ) );
 395+ $codes = array_map( 'trim', explode( ',', $this->opts['language'] ) );
395396
396397 $filters['language'] = trim( $this->opts['language'] ) !== '';
397398 $filters['group'] = trim( $this->opts['group'] ) !== '';
398399
 400+ $namespaces = array();
 401+
399402 foreach ( $groups as $group ) {
 403+ if ( $group === '' ) continue;
 404+ $ns = MessageGroups::getGroup( $group )->getNamespace();
 405+ $namespaces[$ns] = true;
400406
401407 foreach ( $codes as $code ) {
402408 if ( $code !== '' ) $key = "$group ($code)";
@@ -404,9 +410,14 @@
405411 }
406412 }
407413
 414+ if ( count( $namespaces ) ) {
 415+ $conds['rc_namespace'] = array_keys( $namespaces );
 416+ }
 417+
408418 if ( $filters['language'] ) {
409419 $myconds = array();
410420 foreach ( $codes as $code ) {
 421+ if ( $code === '' ) continue;
411422 $myconds[] = 'rc_title like \'%%/' . $db->escapeLike( $code ) . "'";
412423 }
413424
@@ -444,26 +455,35 @@
445456 }
446457
447458 if ( !max( $this->filters ) ) return 0;
448 - if ( strpos( $row->rc_title, '/' ) === false ) return - 1;
 459+ if ( strpos( $row->rc_title, '/' ) === false ) return -1;
 460+ if ( !count( $this->cache ) ) return 0;
449461
450462 list( $key, $code ) = TranslateUtils::figureMessage( $row->rc_title );
451 - $indexKey = '';
 463+ $indexKeys = array();
452464
453465 if ( $this->filters['group'] ) {
454 - $group = TranslateUtils::messageKeyToGroup( $row->rc_namespace, $key );
455 - if ( $group === null ) return - 1;
456 - $indexKey .= $group;
 466+ $groups = TranslateUtils::messageKeyToGroups( $row->rc_namespace, $key );
 467+ if ( !count( $groups ) ) {
 468+ return -1;
 469+ }
 470+ foreach ( $groups as $group ) $indexKeys[] = $group;
457471 }
458472
459473 if ( $this->filters['language'] ) {
460 - $indexKey .= " ($code)";
 474+ foreach ( $indexKeys as &$value ) {
 475+ $value .= " ($code)";
 476+ }
461477 }
462478
463 - if ( count( $this->cache ) ) {
464 - return isset( $this->cache[$indexKey] ) ? $this->cache[$indexKey] : - 1;
465 - } else {
466 - return 0;
 479+ $indexes = array();
 480+
 481+ foreach ( $indexKeys as $value ) {
 482+ if ( isset( $this->cache[$value] ) ) {
 483+ $indexes[] = $this->cache[$value];
 484+ }
467485 }
 486+
 487+ return $indexes;
468488 }
469489
470490 public function labels( &$labels ) {

Status & tagging log