http://www.mediawiki.org/wiki/Special:Code/MediaWiki/84526
Revision: 84526
Author: aaron
Date: 2011-03-22 13:11:28 +0000 (Tue, 22 Mar 2011)
Log Message:
-----------
* Avoid adding DISTINCT if possible
* Added comments
Modified Paths:
--------------
trunk/phase3/includes/LogEventsList.php
Modified: trunk/phase3/includes/LogEventsList.php
===================================================================
--- trunk/phase3/includes/LogEventsList.php 2011-03-22 11:51:09 UTC (rev
84525)
+++ trunk/phase3/includes/LogEventsList.php 2011-03-22 13:11:28 UTC (rev
84526)
@@ -938,12 +938,21 @@
$this->mConds[] = 'user_id = log_user';
$index = array();
$options = array();
- # Add log_search table if there are conditions on it
- if( array_key_exists('ls_field',$this->mConds) ) {
+ # Add log_search table if there are conditions on it.
+ # This filters the results to only include log rows that have
+ # log_search records with the specified ls_field and ls_value
values.
+ if( array_key_exists( 'ls_field', $this->mConds ) ) {
$tables[] = 'log_search';
$index['log_search'] = 'ls_field_val';
$index['logging'] = 'PRIMARY';
- $options[] = 'DISTINCT';
+ if ( !$this->hasEqualsClause( 'ls_field' )
+ || !$this->hasEqualsClause( 'ls_value' ) )
+ {
+ # Since (ls_field,ls_value,ls_logid) is unique,
if the condition is
+ # to match a specific (ls_field,ls_value)
tuple, then there will be
+ # no duplicate log rows. Otherwise, we need to
remove the duplicates.
+ $options[] = 'DISTINCT';
+ }
# Avoid usage of the wrong index by limiting
# the choices of available indexes. This mainly
# avoids site-breaking filesorts.
@@ -967,7 +976,7 @@
'conds' => $this->mConds,
'options' => $options,
'join_conds' => array(
- 'user' => array( 'INNER JOIN',
'user_id=log_user' ),
+ 'user' => array( 'INNER JOIN',
'user_id=log_user' ),
'log_search' => array( 'INNER JOIN',
'ls_log_id=log_id' )
)
);
@@ -977,6 +986,14 @@
return $info;
}
+ // Checks if $this->mConds has $field matched to a *single* value
+ protected function hasEqualsClause( $field ) {
+ return (
+ array_key_exists( $field, $this->mConds ) &&
+ ( !is_array( $this->mConds[$field] ) || count(
$this->mConds[$field] ) == 1 )
+ );
+ }
+
function getIndexField() {
return 'log_timestamp';
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs