From 285be4fd6eb52b7eaf3fa6dcda9626c0414418bf Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 19 Aug 2015 02:25:18 -0700 Subject: [PATCH] Avoid full RC table scans in ChangeTags::updateTags() * Various hooks that add change tags hit this code path now Change-Id: I0b1fe7bef1e691699b2f6462ba7ac22b23253807 --- includes/changetags/ChangeTags.php | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/includes/changetags/ChangeTags.php b/includes/changetags/ChangeTags.php index bf8386f33b..12f738fedb 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -153,8 +153,10 @@ class ChangeTags { * * @since 1.25 */ - public static function updateTags( $tagsToAdd, $tagsToRemove, &$rc_id = null, - &$rev_id = null, &$log_id = null, $params = null ) { + public static function updateTags( + $tagsToAdd, $tagsToRemove, + &$rc_id = null, &$rev_id = null, &$log_id = null, $params = null + ) { $tagsToAdd = array_filter( (array)$tagsToAdd ); // Make sure we're submitting all tags... $tagsToRemove = array_filter( (array)$tagsToRemove ); @@ -169,18 +171,28 @@ class ChangeTags { // Might as well look for rcids and so on. if ( !$rc_id ) { // Info might be out of date, somewhat fractionally, on slave. + // LogEntry/LogPage and WikiPage match rev/log/rc timestamps, + // so use that relation to avoid full table scans. if ( $log_id ) { $rc_id = $dbw->selectField( - 'recentchanges', + array( 'logging', 'recentchanges' ), 'rc_id', - array( 'rc_logid' => $log_id ), + array( + 'log_id' => $log_id, + 'rc_timestamp = log_timestamp', + 'rc_logid = log_id' + ), __METHOD__ ); } elseif ( $rev_id ) { $rc_id = $dbw->selectField( - 'recentchanges', + array( 'revision', 'recentchanges' ), 'rc_id', - array( 'rc_this_oldid' => $rev_id ), + array( + 'rev_id' => $rev_id, + 'rc_timestamp = rev_timestamp', + 'rc_this_oldid = rev_id' + ), __METHOD__ ); } -- 2.20.1