[MediaWiki-commits] [Gerrit] mediawiki/core[master]: API: Add generator non-continuation data
jenkins-bot has submitted this change and it was merged. Change subject: API: Add generator non-continuation data .. API: Add generator non-continuation data Some generators (e.g. generator=recentchanges) in their default mode of operation are particularly prone to not generating the same result set on subsequent requests due to intervening activity on the wiki adding new entries to the start of the list. We can mitigate this effect by allowing such generators to provide "non-continuation" data to be used if the generator isn't being continued. ApiQueryRecentChanges and ApiQueryAllRevisions are updated to set this new property. Other generators can easily be updated in the same way as needed. There isn't anything we can do about generators prone to having entries added at random positions in the list rather than the beginning, unfortunately. Bug: T146176 Change-Id: I8308d6aa2c89fd2a85e74c7dd8a0a2a9ec927490 --- M includes/api/ApiContinuationManager.php M includes/api/ApiQuery.php M includes/api/ApiQueryAllRevisions.php M includes/api/ApiQueryRecentChanges.php 4 files changed, 56 insertions(+), 2 deletions(-) Approvals: Gergő Tisza: Looks good to me, approved jenkins-bot: Verified diff --git a/includes/api/ApiContinuationManager.php b/includes/api/ApiContinuationManager.php index 6601fb7..19e2453 100644 --- a/includes/api/ApiContinuationManager.php +++ b/includes/api/ApiContinuationManager.php @@ -31,6 +31,7 @@ private $continuationData = []; private $generatorContinuationData = []; + private $generatorNonContinuationData = []; private $generatorParams = []; private $generatorDone = false; @@ -143,6 +144,26 @@ } /** +* Set the non-continuation parameter for the generator module +* +* In case the generator isn't going to be continued, this sets the fields +* to return. +* +* @since 1.28 +* @param ApiBase $module +* @param string $paramName +* @param string|array $paramValue +*/ + public function addGeneratorNonContinueParam( ApiBase $module, $paramName, $paramValue ) { + $name = $module->getModuleName(); + $paramName = $module->encodeParamName( $paramName ); + if ( is_array( $paramValue ) ) { + $paramValue = implode( '|', $paramValue ); + } + $this->generatorNonContinuationData[$name][$paramName] = $paramValue; + } + + /** * Set the continuation parameter for the generator module * @param ApiBase $module * @param string $paramName @@ -163,6 +184,15 @@ */ public function getRawContinuation() { return array_merge_recursive( $this->continuationData, $this->generatorContinuationData ); + } + + /** +* Fetch raw non-continuation data +* @since 1.28 +* @return array +*/ + public function getRawNonContinuation() { + return $this->generatorNonContinuationData; } /** @@ -192,8 +222,13 @@ foreach ( $continuationData as $module => $kvp ) { $data += $kvp; } - $data += $this->generatorParams; - $generatorKeys = implode( '|', array_keys( $this->generatorParams ) ); + $generatorParams = []; + foreach ( $this->generatorNonContinuationData as $kvp ) { + $generatorParams += $kvp; + } + $generatorParams += $this->generatorParams; + $data += $generatorParams; + $generatorKeys = implode( '|', array_keys( $generatorParams ) ); } elseif ( $this->generatorContinuationData ) { // All the generator-using modules are complete, but the // generator isn't. Continue the generator and restart the diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 5e3c709..e8aa655 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -258,6 +258,11 @@ // Write the continuation data into the result $this->setContinuationManager( null ); if ( $this->mParams['rawcontinue'] ) { + $data = $continuationManager->getRawNonContinuation(); + if ( $data ) { + $this->getResult()->addValue( null, 'query-noncontinue', $data, + ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK ); + } $data = $continuationManager->getRawContinuation(); if ( $data ) { $this-
[MediaWiki-commits] [Gerrit] mediawiki/core[master]: API: Add generator non-continuation data
Anomie has uploaded a new change for review. https://gerrit.wikimedia.org/r/312076 Change subject: API: Add generator non-continuation data .. API: Add generator non-continuation data Some generators (e.g. generator=recentchanges) in their default mode of operation are particularly prone to not generating the same result set on subsequent requests due to intervening activity on the wiki adding new entries to the start of the list. We can mitigate this effect by allowing such generators to provide "non-continuation" data to be used if the generator isn't being continued. ApiQueryRecentChanges and ApiQueryAllRevisions are updated to set this new property. Other generators can easily be updated in the same way as needed. There isn't anything we can do about generators prone to having entries added at random positions in the list rather than the beginning, unfortunately. Bug: T146176 Change-Id: I8308d6aa2c89fd2a85e74c7dd8a0a2a9ec927490 --- M includes/api/ApiContinuationManager.php M includes/api/ApiQuery.php M includes/api/ApiQueryAllRevisions.php M includes/api/ApiQueryRecentChanges.php 4 files changed, 56 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/76/312076/1 diff --git a/includes/api/ApiContinuationManager.php b/includes/api/ApiContinuationManager.php index 6601fb7..19e2453 100644 --- a/includes/api/ApiContinuationManager.php +++ b/includes/api/ApiContinuationManager.php @@ -31,6 +31,7 @@ private $continuationData = []; private $generatorContinuationData = []; + private $generatorNonContinuationData = []; private $generatorParams = []; private $generatorDone = false; @@ -143,6 +144,26 @@ } /** +* Set the non-continuation parameter for the generator module +* +* In case the generator isn't going to be continued, this sets the fields +* to return. +* +* @since 1.28 +* @param ApiBase $module +* @param string $paramName +* @param string|array $paramValue +*/ + public function addGeneratorNonContinueParam( ApiBase $module, $paramName, $paramValue ) { + $name = $module->getModuleName(); + $paramName = $module->encodeParamName( $paramName ); + if ( is_array( $paramValue ) ) { + $paramValue = implode( '|', $paramValue ); + } + $this->generatorNonContinuationData[$name][$paramName] = $paramValue; + } + + /** * Set the continuation parameter for the generator module * @param ApiBase $module * @param string $paramName @@ -163,6 +184,15 @@ */ public function getRawContinuation() { return array_merge_recursive( $this->continuationData, $this->generatorContinuationData ); + } + + /** +* Fetch raw non-continuation data +* @since 1.28 +* @return array +*/ + public function getRawNonContinuation() { + return $this->generatorNonContinuationData; } /** @@ -192,8 +222,13 @@ foreach ( $continuationData as $module => $kvp ) { $data += $kvp; } - $data += $this->generatorParams; - $generatorKeys = implode( '|', array_keys( $this->generatorParams ) ); + $generatorParams = []; + foreach ( $this->generatorNonContinuationData as $kvp ) { + $generatorParams += $kvp; + } + $generatorParams += $this->generatorParams; + $data += $generatorParams; + $generatorKeys = implode( '|', array_keys( $generatorParams ) ); } elseif ( $this->generatorContinuationData ) { // All the generator-using modules are complete, but the // generator isn't. Continue the generator and restart the diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php index 5e3c709..e8aa655 100644 --- a/includes/api/ApiQuery.php +++ b/includes/api/ApiQuery.php @@ -258,6 +258,11 @@ // Write the continuation data into the result $this->setContinuationManager( null ); if ( $this->mParams['rawcontinue'] ) { + $data = $continuationManager->getRawNonContinuation(); + if ( $data ) { + $this->getResult()->addValue( null, 'query-noncontinue', $data, + ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK ); + } $data = $continuationManager->getRawContinuation(); if ( $data ) {