From 6892c5536df649459bf0543f5a112d19fd53c2ca Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Wed, 3 Feb 2010 23:30:19 +0000 Subject: [PATCH] Fix for r58399 (missing index on change_tag table), using the patch from bug 22032 by Gurch, but altered to respect $wgOldChangeTagsIndex. --- includes/api/ApiQueryLogEvents.php | 12 +++++++----- includes/api/ApiQueryRecentChanges.php | 9 ++++++--- includes/api/ApiQueryRevisions.php | 3 +++ includes/api/ApiQueryUserContributions.php | 7 ++++++- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/includes/api/ApiQueryLogEvents.php b/includes/api/ApiQueryLogEvents.php index 57bec76f43..e2c4b49971 100644 --- a/includes/api/ApiQueryLogEvents.php +++ b/includes/api/ApiQueryLogEvents.php @@ -69,7 +69,7 @@ class ApiQueryLogEvents extends ApiQueryBase { 'page' => array( 'LEFT JOIN', array( 'log_namespace=page_namespace', 'log_title=page_title' ) ) ) ); - $index = 'times'; // default, may change + $index['logging'] = 'times'; // default, may change $this->addFields( array ( 'log_type', @@ -97,11 +97,13 @@ class ApiQueryLogEvents extends ApiQueryBase { $this->addTables( 'change_tag' ); $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'log_id=ct_log_id' ) ) ) ); $this->addWhereFld( 'ct_tag', $params['tag'] ); + global $wgOldChangeTagsIndex; + $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id'; } if ( !is_null( $params['type'] ) ) { $this->addWhereFld( 'log_type', $params['type'] ); - $index = 'type_time'; + $index['logging'] = 'type_time'; } $this->addWhereRange( 'log_timestamp', $params['dir'], $params['start'], $params['end'] ); @@ -115,7 +117,7 @@ class ApiQueryLogEvents extends ApiQueryBase { if ( !$userid ) $this->dieUsage( "User name $user not found", 'param_user' ); $this->addWhereFld( 'log_user', $userid ); - $index = 'user_time'; + $index['logging'] = 'user_time'; } $title = $params['title']; @@ -127,10 +129,10 @@ class ApiQueryLogEvents extends ApiQueryBase { $this->addWhereFld( 'log_title', $titleObj->getDBkey() ); // Use the title index in preference to the user index if there is a conflict - $index = is_null( $user ) ? 'page_time' : array( 'page_time', 'user_time' ); + $index['logging'] = is_null( $user ) ? 'page_time' : array( 'page_time', 'user_time' ); } - $this->addOption( 'USE INDEX', array( 'logging' => $index ) ); + $this->addOption( 'USE INDEX', $index ); // Paranoia: avoid brute force searches (bug 17342) if ( !is_null( $title ) ) { diff --git a/includes/api/ApiQueryRecentChanges.php b/includes/api/ApiQueryRecentChanges.php index 2c6798299a..0eb7dbd5ee 100644 --- a/includes/api/ApiQueryRecentChanges.php +++ b/includes/api/ApiQueryRecentChanges.php @@ -114,7 +114,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { */ $db = $this->getDB(); $this->addTables( 'recentchanges' ); - $index = 'rc_timestamp'; // May change + $index['recentchanges'] = 'rc_timestamp'; // May change $this->addWhereRange( 'rc_timestamp', $params['dir'], $params['start'], $params['end'] ); $this->addWhereFld( 'rc_namespace', $params['namespace'] ); $this->addWhereFld( 'rc_deleted', 0 ); @@ -161,7 +161,7 @@ class ApiQueryRecentChanges extends ApiQueryBase { if ( !is_null( $params['user'] ) ) { $this->addWhereFld( 'rc_user_text', $params['user'] ); - $index = 'rc_user_text'; + $index['recentchanges'] = 'rc_user_text'; } if ( !is_null( $params['excludeuser'] ) ) @@ -227,10 +227,13 @@ class ApiQueryRecentChanges extends ApiQueryBase { $this->addTables( 'change_tag' ); $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rc_id=ct_rc_id' ) ) ) ); $this->addWhereFld( 'ct_tag' , $params['tag'] ); + global $wgOldChangeTagsIndex; + $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id'; } + $this->token = $params['token']; $this->addOption( 'LIMIT', $params['limit'] + 1 ); - $this->addOption( 'USE INDEX', array( 'recentchanges' => $index ) ); + $this->addOption( 'USE INDEX', $index ); $count = 0; /* Perform the actual query. */ diff --git a/includes/api/ApiQueryRevisions.php b/includes/api/ApiQueryRevisions.php index 9a98e7d4a1..4a2af3aa9f 100644 --- a/includes/api/ApiQueryRevisions.php +++ b/includes/api/ApiQueryRevisions.php @@ -157,6 +157,8 @@ class ApiQueryRevisions extends ApiQueryBase { $this->addTables( 'change_tag' ); $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) ); $this->addWhereFld( 'ct_tag' , $params['tag'] ); + global $wgOldChangeTagsIndex; + $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id'; } if ( isset( $prop['content'] ) || !is_null( $this->difftotext ) ) { @@ -295,6 +297,7 @@ class ApiQueryRevisions extends ApiQueryBase { ApiBase :: dieDebug( __METHOD__, 'param validation?' ); $this->addOption( 'LIMIT', $limit + 1 ); + $this->addOption( 'USE INDEX', $index ); $data = array (); $count = 0; diff --git a/includes/api/ApiQueryUserContributions.php b/includes/api/ApiQueryUserContributions.php index ad735189b7..4a52f287f0 100644 --- a/includes/api/ApiQueryUserContributions.php +++ b/includes/api/ApiQueryUserContributions.php @@ -238,7 +238,6 @@ class ApiQueryContributions extends ApiQueryBase { } $this->addTables( $tables ); - $this->addOption( 'USE INDEX', $index ); $this->addFieldsIf( 'rev_page', $this->fld_ids ); $this->addFieldsIf( 'rev_id', $this->fld_ids || $this->fld_flags ); $this->addFieldsIf( 'page_latest', $this->fld_flags ); @@ -260,7 +259,11 @@ class ApiQueryContributions extends ApiQueryBase { $this->addTables( 'change_tag' ); $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) ); $this->addWhereFld( 'ct_tag', $this->params['tag'] ); + global $wgOldChangeTagsIndex; + $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id'; } + + $this->addOption( 'USE INDEX', $index ); } /** @@ -390,6 +393,7 @@ class ApiQueryContributions extends ApiQueryBase { '!patrolled', ) ), + 'tag' => null, ); } @@ -406,6 +410,7 @@ class ApiQueryContributions extends ApiQueryBase { 'prop' => 'Include additional pieces of information', 'show' => array( 'Show only items that meet this criteria, e.g. non minor edits only: show=!minor', 'NOTE: if show=patrolled or show=!patrolled is set, revisions older than $wgRCMaxAge won\'t be shown', ), + 'tag' => 'Only list revisions tagged with this tag', ); } -- 2.20.1