API: Add "batchcomplete" to simplified continuation result
authorBrad Jorsch <bjorsch@wikimedia.org>
Wed, 6 Aug 2014 08:56:53 +0000 (09:56 +0100)
committerKunal Mehta <legoktm@gmail.com>
Mon, 13 Oct 2014 22:26:45 +0000 (15:26 -0700)
With the query-continue style of continuation, it's easy for the client
to know when a batch of pages from the generator is complete. The
simplified continuation should support this too, and without requiring
the client to parse the "continue" result property.

Change-Id: Ie407e2e27c017e8813143859cc58674553bc641b

RELEASE-NOTES-1.25
includes/api/ApiResult.php
tests/phpunit/includes/api/query/ApiQueryContinue2Test.php
tests/phpunit/includes/api/query/ApiQueryContinueTest.php

index 69c5375..717f0c6 100644 (file)
@@ -45,6 +45,8 @@ production.
   "uselang=user" may be used to select the language from the current user's
   preferences.
 * Default output format for the API is now jsonfm.
+* Simplified continuation will return a "batchcomplete" property in the result
+  when a batch of pages is complete.
 
 === Action API internal changes in 1.25 ===
 * ApiHelp has been rewritten to support i18n and paginated HTML output.
index 2e80447..946977d 100644 (file)
@@ -569,6 +569,7 @@ class ApiResult extends ApiBase {
                } else {
                        $key = 'continue';
                        $data = array();
+                       $batchcomplete = false;
 
                        $finishedModules = array_diff(
                                array_keys( $this->continueAllModules ),
@@ -611,9 +612,11 @@ class ApiResult extends ApiBase {
                                $finishedModules = array_diff(
                                        $finishedModules, $this->continueGeneratedModules
                                );
+                               $batchcomplete = true;
                        } else {
                                // Generator and prop modules are all done. Mark it so.
                                $this->generatorDone = true;
+                               $batchcomplete = true;
                        }
 
                        // Set 'continue' if any continuation data is set or if the generator
@@ -623,6 +626,10 @@ class ApiResult extends ApiBase {
                                        ( $this->generatorDone ? '-' : join( '|', $this->generatorParams ) ) .
                                        '||' . join( '|', $finishedModules );
                        }
+
+                       if ( $batchcomplete ) {
+                               $this->addValue( null, 'batchcomplete', '', ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
+                       }
                }
                if ( $data ) {
                        $this->addValue( null, $key, $data, ApiResult::ADD_ON_TOP | ApiResult::NO_SIZE_CHECK );
index 347cd6f..46f1b7b 100644 (file)
@@ -62,7 +62,8 @@ class ApiQueryContinue2Test extends ApiQueryContinueTestBase {
                        );
                };
                // generator + 1 prop + 1 list
-               $data = $this->query( $mk( 99, 99, true ), 1, 'g1p', false );
+               $data = $this->query( $mk( 99, 99, true ), 1, 'g1p', false ) +
+                       array( 'batchcomplete' => '' );
                $this->checkC( $data, $mk( 1, 1, true ), 6, 'g1p-11t' );
                $this->checkC( $data, $mk( 2, 2, true ), 3, 'g1p-22t' );
                $this->checkC( $data, $mk( 1, 1, false ), 6, 'g1p-11f' );
index 0379790..328d839 100644 (file)
@@ -68,7 +68,8 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                                'aplimit' => "$l",
                        );
                };
-               $data = $this->query( $mk( 99 ), 1, '1L', false );
+               $data = $this->query( $mk( 99 ), 1, '1L', false ) +
+                       array( 'batchcomplete' => '' );
 
                // 1 list
                $this->checkC( $data, $mk( 1 ), 5, '1L-1' );
@@ -95,7 +96,8 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                        );
                };
                // 2 lists
-               $data = $this->query( $mk( 99, 99 ), 1, '2L', false );
+               $data = $this->query( $mk( 99, 99 ), 1, '2L', false ) +
+                       array( 'batchcomplete' => '' );
                $this->checkC( $data, $mk( 1, 1 ), 5, '2L-11' );
                $this->checkC( $data, $mk( 2, 2 ), 3, '2L-22' );
                $this->checkC( $data, $mk( 3, 3 ), 2, '2L-33' );
@@ -119,7 +121,8 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                        );
                };
                // generator + 1 prop
-               $data = $this->query( $mk( 99, 99 ), 1, 'G1P', false );
+               $data = $this->query( $mk( 99, 99 ), 1, 'G1P', false ) +
+                       array( 'batchcomplete' => '' );
                $this->checkC( $data, $mk( 1, 1 ), 11, 'G1P-11' );
                $this->checkC( $data, $mk( 2, 2 ), 6, 'G1P-22' );
                $this->checkC( $data, $mk( 3, 3 ), 4, 'G1P-33' );
@@ -144,7 +147,8 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                        );
                };
                // generator + 2 props
-               $data = $this->query( $mk( 99, 99, 99 ), 1, 'G2P', false );
+               $data = $this->query( $mk( 99, 99, 99 ), 1, 'G2P', false ) +
+                       array( 'batchcomplete' => '' );;
                $this->checkC( $data, $mk( 1, 1, 1 ), 16, 'G2P-111' );
                $this->checkC( $data, $mk( 2, 2, 2 ), 9, 'G2P-222' );
                $this->checkC( $data, $mk( 3, 3, 3 ), 6, 'G2P-333' );
@@ -177,7 +181,8 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                        );
                };
                // generator + 1 prop + 1 list
-               $data = $this->query( $mk( 99, 99, 99 ), 1, 'G1P1L', false );
+               $data = $this->query( $mk( 99, 99, 99 ), 1, 'G1P1L', false ) +
+                       array( 'batchcomplete' => '' );
                $this->checkC( $data, $mk( 1, 1, 1 ), 11, 'G1P1L-111' );
                $this->checkC( $data, $mk( 2, 2, 2 ), 6, 'G1P1L-222' );
                $this->checkC( $data, $mk( 3, 3, 3 ), 4, 'G1P1L-333' );
@@ -214,7 +219,8 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                        );
                };
                // generator + 1 prop + 1 list
-               $data = $this->query( $mk( 99, 99, 99, 99, 99 ), 1, 'G2P2L1M', false );
+               $data = $this->query( $mk( 99, 99, 99, 99, 99 ), 1, 'G2P2L1M', false ) +
+                       array( 'batchcomplete' => '' );
                $this->checkC( $data, $mk( 1, 1, 1, 1, 1 ), 16, 'G2P2L1M-11111' );
                $this->checkC( $data, $mk( 2, 2, 2, 2, 2 ), 9, 'G2P2L1M-22222' );
                $this->checkC( $data, $mk( 3, 3, 3, 3, 3 ), 6, 'G2P2L1M-33333' );
@@ -244,7 +250,8 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                        );
                };
                // generator + 1 prop
-               $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false );
+               $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=P', false ) +
+                       array( 'batchcomplete' => '' );
 
                $this->checkC( $data, $mk( 1, true, 1, true ), 4, 'G=P-1t1t' );
                $this->checkC( $data, $mk( 2, true, 2, true ), 2, 'G=P-2t2t' );
@@ -290,7 +297,8 @@ class ApiQueryContinueTest extends ApiQueryContinueTestBase {
                        );
                };
                // generator + 1 list
-               $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false );
+               $data = $this->query( $mk( 99, true, 99, true ), 1, 'G=L', false ) +
+                       array( 'batchcomplete' => '' );
 
                $this->checkC( $data, $mk( 1, true, 1, true ), 5, 'G=L-1t1t' );
                $this->checkC( $data, $mk( 2, true, 2, true ), 3, 'G=L-2t2t' );