r84526 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84525‎ | r84526 | r84527 >
Date:13:11, 22 March 2011
Author:aaron
Status:ok
Tags:
Comment:
* Avoid adding DISTINCT if possible
* Added comments
Modified paths:
  • /trunk/phase3/includes/LogEventsList.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/LogEventsList.php
@@ -938,12 +938,21 @@
939939 $this->mConds[] = 'user_id = log_user';
940940 $index = array();
941941 $options = array();
942 - # Add log_search table if there are conditions on it
943 - if( array_key_exists('ls_field',$this->mConds) ) {
 942+ # Add log_search table if there are conditions on it.
 943+ # This filters the results to only include log rows that have
 944+ # log_search records with the specified ls_field and ls_value values.
 945+ if( array_key_exists( 'ls_field', $this->mConds ) ) {
944946 $tables[] = 'log_search';
945947 $index['log_search'] = 'ls_field_val';
946948 $index['logging'] = 'PRIMARY';
947 - $options[] = 'DISTINCT';
 949+ if ( !$this->hasEqualsClause( 'ls_field' )
 950+ || !$this->hasEqualsClause( 'ls_value' ) )
 951+ {
 952+ # Since (ls_field,ls_value,ls_logid) is unique, if the condition is
 953+ # to match a specific (ls_field,ls_value) tuple, then there will be
 954+ # no duplicate log rows. Otherwise, we need to remove the duplicates.
 955+ $options[] = 'DISTINCT';
 956+ }
948957 # Avoid usage of the wrong index by limiting
949958 # the choices of available indexes. This mainly
950959 # avoids site-breaking filesorts.
@@ -967,7 +976,7 @@
968977 'conds' => $this->mConds,
969978 'options' => $options,
970979 'join_conds' => array(
971 - 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
 980+ 'user' => array( 'INNER JOIN', 'user_id=log_user' ),
972981 'log_search' => array( 'INNER JOIN', 'ls_log_id=log_id' )
973982 )
974983 );
@@ -977,6 +986,14 @@
978987 return $info;
979988 }
980989
 990+ // Checks if $this->mConds has $field matched to a *single* value
 991+ protected function hasEqualsClause( $field ) {
 992+ return (
 993+ array_key_exists( $field, $this->mConds ) &&
 994+ ( !is_array( $this->mConds[$field] ) || count( $this->mConds[$field] ) == 1 )
 995+ );
 996+ }
 997+
981998 function getIndexField() {
982999 return 'log_timestamp';
9831000 }

Sign-offs

UserFlagDate
Hasharinspected18:21, 4 July 2011

Status & tagging log