You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2018/01/16 14:52:39 UTC

[GitHub] eiri closed pull request #1085: Return update_seq and offset when update_seq is true and keys is set

eiri closed pull request #1085: Return update_seq and offset when update_seq is true and keys is set
URL: https://github.com/apache/couchdb/pull/1085
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/chttpd/test/chttpd_db_test.erl b/src/chttpd/test/chttpd_db_test.erl
index f3c779bd32..a83e33accd 100644
--- a/src/chttpd/test/chttpd_db_test.erl
+++ b/src/chttpd/test/chttpd_db_test.erl
@@ -20,6 +20,7 @@
 -define(AUTH, {basic_auth, {?USER, ?PASS}}).
 -define(CONTENT_JSON, {"Content-Type", "application/json"}).
 -define(FIXTURE_TXT, ?ABS_PATH(?FILE)).
+-define(i2l(I), integer_to_list(I)).
 
 setup() ->
     Hashed = couch_passwords:hash_admin_password(?PASS),
@@ -62,7 +63,9 @@ all_test_() ->
                     fun should_return_404_for_delete_att_on_notadoc/1,
                     fun should_return_409_for_del_att_without_rev/1,
                     fun should_return_200_for_del_att_with_rev/1,
-                    fun should_return_409_for_put_att_nonexistent_rev/1
+                    fun should_return_409_for_put_att_nonexistent_rev/1,
+                    fun should_return_update_seq_when_set_on_all_docs/1,
+                    fun should_not_return_update_seq_when_unset_on_all_docs/1
                 ]
             }
         }
@@ -187,6 +190,34 @@ should_return_409_for_put_att_nonexistent_rev(Url) ->
     end).
 
 
+should_return_update_seq_when_set_on_all_docs(Url) ->
+    ?_test(begin
+        [create_doc(Url, "testdoc" ++ ?i2l(I)) || I <- lists:seq(1, 3)],
+        {ok, RC, _, RespBody} = test_request:get(Url ++ "/_all_docs/"
+            ++ "?update_seq=true&keys=[\"testdoc1\"]",[?CONTENT_JSON, ?AUTH]),
+        ?assertEqual(200, RC),
+        {ResultJson} = ?JSON_DECODE(RespBody),
+        ?assertNotEqual(undefined,
+            couch_util:get_value(<<"update_seq">>, ResultJson)),
+        ?assertNotEqual(undefined,
+            couch_util:get_value(<<"offset">>, ResultJson))
+    end).
+
+
+should_not_return_update_seq_when_unset_on_all_docs(Url) ->
+    ?_test(begin
+        [create_doc(Url, "testdoc" ++ ?i2l(I)) || I <- lists:seq(1, 3)],
+        {ok, RC, _, RespBody} = test_request:get(Url ++ "/_all_docs/"
+            ++ "?update_seq=false&keys=[\"testdoc1\"]",[?CONTENT_JSON, ?AUTH]),
+        ?assertEqual(200, RC),
+        {ResultJson} = ?JSON_DECODE(RespBody),
+        ?assertEqual(undefined,
+            couch_util:get_value(<<"update_seq">>, ResultJson)),
+        ?assertNotEqual(undefined,
+            couch_util:get_value(<<"offset">>, ResultJson))
+    end).
+
+
 attachment_doc() ->
     {ok, Data} = file:read_file(?FIXTURE_TXT),
     {[
diff --git a/src/fabric/src/fabric_view_all_docs.erl b/src/fabric/src/fabric_view_all_docs.erl
index de21dde08d..ac16dac526 100644
--- a/src/fabric/src/fabric_view_all_docs.erl
+++ b/src/fabric/src/fabric_view_all_docs.erl
@@ -59,7 +59,8 @@ go(DbName, Options, QueryArgs, Callback, Acc0) ->
         conflicts = Conflicts,
         skip = Skip,
         keys = Keys0,
-        extra = Extra
+        extra = Extra,
+        update_seq = UpdateSeq
     } = QueryArgs,
     DocOptions1 = case Conflicts of
         true -> [conflicts|DocOptions0];
@@ -97,7 +98,12 @@ go(DbName, Options, QueryArgs, Callback, Acc0) ->
     end,
     case Resp of
         {ok, TotalRows} ->
-            {ok, Acc1} = Callback({meta, [{total, TotalRows}]}, Acc0),
+            Meta = case UpdateSeq of
+                false -> [{total, TotalRows}, {offset, null}];
+                true ->
+                    [{total, TotalRows}, {offset, null}, {update_seq, null}]
+            end,
+            {ok, Acc1} = Callback({meta, Meta}, Acc0),
             {ok, Acc2} = doc_receive_loop(
                 Keys3, queue:new(), SpawnFun, MaxJobs, Callback, Acc1
             ),


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services