You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2019/08/29 21:32:13 UTC

[couchdb] branch prototype/fdb-layer updated: Fix starkey_docid, endkey_docid and inclusive_end=false for _all_docs

This is an automated email from the ASF dual-hosted git repository.

vatamane pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/prototype/fdb-layer by this push:
     new dc1b4b8  Fix starkey_docid, endkey_docid and inclusive_end=false for _all_docs
dc1b4b8 is described below

commit dc1b4b8f1850a5aca77e40aee69202a0d22c287f
Author: Nick Vatamaniuc <va...@apache.org>
AuthorDate: Thu Aug 29 16:22:49 2019 -0400

    Fix starkey_docid, endkey_docid and inclusive_end=false for _all_docs
---
 src/chttpd/src/chttpd_db.erl | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index dbb92fa..42cbb7d 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -838,15 +838,7 @@ all_docs_view(Req, Db, Keys, OP) ->
     },
     case Args1#mrargs.keys of
         undefined ->
-            Options = [
-                {user_ctx, Req#httpd.user_ctx},
-                {dir, Args1#mrargs.direction},
-                {start_key, Args1#mrargs.start_key},
-                {end_key, Args1#mrargs.end_key},
-                {limit, Args1#mrargs.limit},
-                {skip, Args1#mrargs.skip},
-                {update_seq, Args1#mrargs.update_seq}
-            ],
+            Options = all_docs_view_opts(Args1, Req),
             Acc = {iter, Db, Args1, VAcc0},
             {ok, {iter, _, _, Resp}} =
                     fabric2_db:fold_docs(Db, fun view_cb/2, Acc, Options),
@@ -919,6 +911,29 @@ all_docs_view(Req, Db, Keys, OP) ->
     end.
 
 
+all_docs_view_opts(Args, Req) ->
+    StartKey = case Args#mrargs.start_key of
+        undefined -> Args#mrargs.start_key_docid;
+        SKey -> SKey
+    end,
+    EndKey = case Args#mrargs.end_key of
+        undefined -> Args#mrargs.end_key_docid;
+        EKey -> EKey
+    end,
+    EndKeyOpts = case {EndKey, Args#mrargs.inclusive_end} of
+        {<<_/binary>>, false} -> [{end_key_gt, EndKey}];
+        {_, _} -> [{end_key, EndKey}]
+    end,
+    [
+        {user_ctx, Req#httpd.user_ctx},
+        {dir, Args#mrargs.direction},
+        {start_key, StartKey},
+        {limit, Args#mrargs.limit},
+        {skip, Args#mrargs.skip},
+        {update_seq, Args#mrargs.update_seq}
+    ] ++ EndKeyOpts.
+
+
 apply_args_to_keylist(Args, Keys0) ->
     Keys1 = case Args#mrargs.direction of
         fwd -> Keys0;