From d4efceaac90b32088a37fa0a82dff5e251a0b6c6 Mon Sep 17 00:00:00 2001 From: Amir Sarabadani Date: Tue, 4 Sep 2018 20:58:41 +0200 Subject: [PATCH] Join decomposition on change_tag and change_tag_def when filtering Since the service uses cache and MySQL also caches, this is faster Bug: T194162 Change-Id: I57bbbf4f566d8140f9f80c16ecc454f857d363b2 --- 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 0bb84840f0..008a2f6f19 100644 --- a/includes/changetags/ChangeTags.php +++ b/includes/changetags/ChangeTags.php @@ -22,6 +22,7 @@ */ use MediaWiki\MediaWikiServices; +use MediaWiki\Storage\NameTableAccessException; use Wikimedia\Rdbms\Database; class ChangeTags { @@ -802,16 +803,18 @@ class ChangeTags { throw new MWException( 'Unable to determine appropriate JOIN condition for tagging.' ); } + $tagTables[] = 'change_tag'; if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $tables[] = 'change_tag_def'; - $join_cond = [ $join_cond, 'ct_tag_id=ctd_id' ]; + $tagTables[] = 'change_tag_def'; + $join_cond_ts_tags = [ $join_cond, 'ct_tag_id=ctd_id' ]; $field = 'ctd_name'; } else { $field = 'ct_tag'; + $join_cond_ts_tags = $join_cond; } $fields['ts_tags'] = wfGetDB( DB_REPLICA )->buildGroupConcatField( - ',', 'change_tag', $field, $join_cond + ',', $tagTables, $field, $join_cond_ts_tags ); if ( $wgUseTagFilter && $filter_tag ) { @@ -821,9 +824,18 @@ class ChangeTags { $tables[] = 'change_tag'; $join_conds['change_tag'] = [ 'INNER JOIN', $join_cond ]; if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) { - $tables[] = 'change_tag_def'; - $join_conds['change_tag_def'] = [ 'INNER JOIN', 'ct_tag_id=ctd_id' ]; - $conds['ctd_name'] = $filter_tag; + $filterTagIds = []; + $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore(); + foreach ( (array)$filter_tag as $filterTagName ) { + try { + $filterTagIds[] = $changeTagDefStore->getId( $filterTagName ); + } catch ( NameTableAccessException $exception ) { + // Return nothing. + $conds[] = '0'; + break; + }; + } + $conds['ct_tag_id'] = $filterTagIds; } else { $conds['ct_tag'] = $filter_tag; } -- 2.20.1