jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/355864 )
Change subject: Chunk page ids in internal API call to avoid too-many-pageids-for-query ...................................................................... Chunk page ids in internal API call to avoid too-many-pageids-for-query One of many reasons that internal API calls are bad. Bug: T41936 Change-Id: I338b444087c7570e455469e2c0fad8f5ca46644e --- M includes/PageImages.php 1 file changed, 26 insertions(+), 23 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/PageImages.php b/includes/PageImages.php index 4a8004b..0f90aff 100644 --- a/includes/PageImages.php +++ b/includes/PageImages.php @@ -163,32 +163,35 @@ * @return array[] */ private static function getImages( array $pageIds, $size = 0 ) { - $request = [ - 'action' => 'query', - 'prop' => 'pageimages', - 'piprop' => 'name', - 'pageids' => implode( '|', $pageIds ), - 'pilimit' => 'max', - ]; + $ret = []; + foreach ( array_chunk( $pageIds, ApiBase::LIMIT_SML1 ) as $chunk ) { + $request = [ + 'action' => 'query', + 'prop' => 'pageimages', + 'piprop' => 'name', + 'pageids' => implode( '|', $chunk ), + 'pilimit' => 'max', + ]; - if ( $size ) { - $request['piprop'] = 'thumbnail'; - $request['pithumbsize'] = $size; - } - - $api = new ApiMain( new FauxRequest( $request ) ); - $api->execute(); - - if ( defined( 'ApiResult::META_CONTENT' ) ) { - return (array)$api->getResult()->getResultData( [ 'query', 'pages' ], - [ 'Strip' => 'base' ] ); - } else { - $data = $api->getResultData(); - if ( isset( $data['query']['pages'] ) ) { - return $data['query']['pages']; + if ( $size ) { + $request['piprop'] = 'thumbnail'; + $request['pithumbsize'] = $size; } - return []; + + $api = new ApiMain( new FauxRequest( $request ) ); + $api->execute(); + + if ( defined( 'ApiResult::META_CONTENT' ) ) { + $ret += (array)$api->getResult()->getResultData( [ 'query', 'pages' ], + [ 'Strip' => 'base' ] ); + } else { + $data = $api->getResultData(); + if ( isset( $data['query']['pages'] ) ) { + $ret += $data['query']['pages']; + } + } } + return $ret; } public static function onRegistration() { -- To view, visit https://gerrit.wikimedia.org/r/355864 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I338b444087c7570e455469e2c0fad8f5ca46644e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/PageImages Gerrit-Branch: master Gerrit-Owner: Anomie <bjor...@wikimedia.org> Gerrit-Reviewer: Legoktm <lego...@member.fsf.org> Gerrit-Reviewer: Reedy <re...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits