X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiQueryUserContribs.php;h=0ca0b20a2ed02a30eee222771586eda1273297af;hb=46ae5683a04ad6d73a504b50b7bb7253df9f5c77;hp=ae7c580c2ca442d174a735fdaffdae1764b30a1f;hpb=32b573187dd9c70739b3c86f67bc11b92a183519;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiQueryUserContribs.php b/includes/api/ApiQueryUserContribs.php index ae7c580c2c..0ca0b20a2e 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' ? '<' : '>' ); @@ -136,7 +133,7 @@ class ApiQueryUserContribs extends ApiQueryBase { // prepareQuery might try to sort by actor and confuse everything. $batchSize = 1; } elseif ( isset( $this->params['userids'] ) ) { - if ( !count( $this->params['userids'] ) ) { + if ( $this->params['userids'] === [] ) { $encParamName = $this->encodeParamName( 'userids' ); $this->dieWithError( [ 'apierror-paramempty', $encParamName ], "paramempty_$encParamName" ); } @@ -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(); @@ -478,11 +482,7 @@ class ApiQueryUserContribs extends ApiQueryBase { $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled ); if ( $this->fld_tags ) { - $this->addTables( 'tag_summary' ); - $this->addJoinConds( - [ 'tag_summary' => [ 'LEFT JOIN', [ $idField . ' = ts_rev_id' ] ] ] - ); - $this->addFields( 'ts_tags' ); + $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'revision' ) ] ); } if ( isset( $this->params['tag'] ) ) { @@ -523,12 +523,12 @@ class ApiQueryUserContribs extends ApiQueryBase { $anyHidden = true; } if ( $this->fld_ids ) { - $vals['pageid'] = intval( $row->rev_page ); - $vals['revid'] = intval( $row->rev_id ); - // $vals['textid'] = intval( $row->rev_text_id ); // todo: Should this field be exposed? + $vals['pageid'] = (int)$row->rev_page; + $vals['revid'] = (int)$row->rev_id; + // $vals['textid'] = (int)$row->rev_text_id; // todo: Should this field be exposed? if ( !is_null( $row->rev_parent_id ) ) { - $vals['parentid'] = intval( $row->rev_parent_id ); + $vals['parentid'] = (int)$row->rev_parent_id; } } @@ -577,7 +577,7 @@ class ApiQueryUserContribs extends ApiQueryBase { } if ( $this->fld_size && !is_null( $row->rev_len ) ) { - $vals['size'] = intval( $row->rev_len ); + $vals['size'] = (int)$row->rev_len; } if ( $this->fld_sizediff @@ -585,7 +585,7 @@ class ApiQueryUserContribs extends ApiQueryBase { && !is_null( $row->rev_parent_id ) ) { $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0; - $vals['sizediff'] = intval( $row->rev_len - $parentLen ); + $vals['sizediff'] = (int)$row->rev_len - $parentLen; } if ( $this->fld_tags ) {