mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/PageImages
synced 2024-11-15 03:43:46 +00:00
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
This commit is contained in:
parent
9b63fdc577
commit
b7b6185dae
|
@ -163,32 +163,35 @@ class PageImages {
|
|||
* @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;
|
||||
}
|
||||
|
||||
$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 [];
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
public static function onRegistration() {
|
||||
|
|
Loading…
Reference in a new issue