From: Brad Jorsch Date: Thu, 21 Feb 2019 15:47:07 +0000 (-0500) Subject: ApiQueryUserContribs: Only use 'contributions' replica if querying by user ID X-Git-Tag: 1.34.0-rc.0~2751^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=fe65f68588638d9f067580a341f8de3d3a85394f;hp=1900a8a12e8e1445fa8b9cca46a89354fcc88f1d;p=lhc%2Fweb%2Fwiklou.git ApiQueryUserContribs: Only use 'contributions' replica if querying by user ID When querying by user name or actor ID, the partitioning on the 'contributions' replicas makes things worse rather than better. Bug: T216656 Change-Id: Ib4caf19d8fad64c527dee99667e425fd3e4b1a16 --- diff --git a/includes/api/ApiQueryUserContribs.php b/includes/api/ApiQueryUserContribs.php index 60826178b4..ae1be0d4ef 100644 --- a/includes/api/ApiQueryUserContribs.php +++ b/includes/api/ApiQueryUserContribs.php @@ -61,14 +61,11 @@ class ApiQueryUserContribs extends ApiQueryBase { $this->fld_patrolled = isset( $prop['patrolled'] ); $this->fld_tags = isset( $prop['tags'] ); - // Most of this code will use the 'contributions' group DB, which can map to replica DBs + // The main query may use the 'contributions' group DB, which can map to replica DBs // with extra user based indexes or partioning by user. The additional metadata // queries should use a regular replica DB since the lookup pattern is not all by user. $dbSecondary = $this->getDB(); // any random replica DB - // TODO: if the query is going only against the revision table, should this be done? - $this->selectNamedDB( 'contributions', DB_REPLICA, 'contributions' ); - $sort = ( $this->params['dir'] == 'newer' ? '' : ' DESC' ); $op = ( $this->params['dir'] == 'older' ? '<' : '>' ); @@ -269,6 +266,13 @@ class ApiQueryUserContribs extends ApiQueryBase { $this->orderBy = 'actor'; } + // Use the 'contributions' replica, but only if we're querying by user ID (T216656). + if ( $this->orderBy === 'id' && + !( $wgActorTableSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) + ) { + $this->selectNamedDB( 'contributions', DB_REPLICA, 'contributions' ); + } + $count = 0; $limit = $this->params['limit']; $userIter->rewind();