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 2020/07/21 13:51:23 UTC

[GitHub] [couchdb] garrensmith commented on a change in pull request #2904: Add support for previous bookmark

garrensmith commented on a change in pull request #2904:
URL: https://github.com/apache/couchdb/pull/2904#discussion_r458110597



##########
File path: src/couch_views/src/couch_views_http.erl
##########
@@ -143,21 +144,29 @@ do_paginated(PageSize, QueriesArgs, KeyFun, Fun) when is_list(QueriesArgs) ->
     lists:reverse(Results).
 
 
-maybe_add_bookmark(OriginalLimit, PageSize, Args0, Response, Items, KeyFun) ->
-    #mrargs{page_size = RequestedLimit} = Args0,
+maybe_add_next_bookmark(OriginalLimit, PageSize, Args0, Response, Items, KeyFun) ->
+    #mrargs{
+        page_size = RequestedLimit,
+        extra = Extra
+    } = Args0,
     case check_completion(OriginalLimit, RequestedLimit, Items) of
         {Rows, nil} ->
             maps:merge(Response, #{
                 rows => Rows,
                 total_rows => length(Rows)
             });
         {Rows, Next} ->
+            FirstKey = first_key(KeyFun, Rows),
             NextKey = KeyFun(Next),
             if is_binary(NextKey) -> ok; true ->
                 throw("Provided KeyFun should return binary")
             end,
-            Args = Args0#mrargs{page_size = PageSize},
-            Bookmark = bookmark_encode(Args#mrargs{start_key=NextKey}),
+            Args = Args0#mrargs{
+                page_size = PageSize,
+                start_key = NextKey,
+                extra = lists:keystore(fk, 1, Extra, {fk, FirstKey})
+            },
+            Bookmark = bookmark_encode(Args),

Review comment:
       With maps you can do:
   ```
   Response#{
      rows => Rows,
      next => BookMark
   }
   ```
   That is the same as using `maps:merge` and you can use it instead of doing a `maps:put` as well. But this depends on which style you prefer.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to 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