jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/355863 )
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: I3d2cf2b4f619f590e74a88fa4a78832b8be8495e --- M includes/Hooks.php 1 file changed, 22 insertions(+), 20 deletions(-) Approvals: Legoktm: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/Hooks.php b/includes/Hooks.php index 36f8905..7c88f30 100644 --- a/includes/Hooks.php +++ b/includes/Hooks.php @@ -2,6 +2,7 @@ namespace TextExtracts; +use ApiBase; use ApiMain; use ApiResult; use FauxRequest; @@ -19,26 +20,27 @@ if ( !$config->get( 'ExtractsExtendOpenSearchXml' ) || !count( $results ) ) { return true; } - $pageIds = array_keys( $results ); - $api = new ApiMain( new FauxRequest( - [ - 'action' => 'query', - 'prop' => 'extracts', - 'explaintext' => true, - 'exintro' => true, - 'exlimit' => count( $results ), - 'pageids' => implode( '|', $pageIds ), - ] ) - ); - $api->execute(); - $data = $api->getResult()->getResultData( [ 'query', 'pages' ] ); - foreach ( $pageIds as $id ) { - $contentKey = isset( $data[$id]['extract'][ApiResult::META_CONTENT] ) - ? $data[$id]['extract'][ApiResult::META_CONTENT] - : '*'; - if ( isset( $data[$id]['extract'][$contentKey] ) ) { - $results[$id]['extract'] = $data[$id]['extract'][$contentKey]; - $results[$id]['extract trimmed'] = false; + foreach ( array_chunk( array_keys( $results ), ApiBase::LIMIT_SML1 ) as $pageIds ) { + $api = new ApiMain( new FauxRequest( + [ + 'action' => 'query', + 'prop' => 'extracts', + 'explaintext' => true, + 'exintro' => true, + 'exlimit' => count( $pageIds ), + 'pageids' => implode( '|', $pageIds ), + ] ) + ); + $api->execute(); + $data = $api->getResult()->getResultData( [ 'query', 'pages' ] ); + foreach ( $pageIds as $id ) { + $contentKey = isset( $data[$id]['extract'][ApiResult::META_CONTENT] ) + ? $data[$id]['extract'][ApiResult::META_CONTENT] + : '*'; + if ( isset( $data[$id]['extract'][$contentKey] ) ) { + $results[$id]['extract'] = $data[$id]['extract'][$contentKey]; + $results[$id]['extract trimmed'] = false; + } } } return true; -- To view, visit https://gerrit.wikimedia.org/r/355863 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I3d2cf2b4f619f590e74a88fa4a78832b8be8495e Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/TextExtracts 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