couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From beno...@apache.org
Subject [4/7] couch-mrview commit: updated refs/heads/1994-merge-rcouch to 4e0f295
Date Sun, 13 Jul 2014 12:29:44 GMT
fix: make sure we only get results from last sequence when using a
composite key.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/91df48a1
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/91df48a1
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/91df48a1

Branch: refs/heads/1994-merge-rcouch
Commit: 91df48a16db0277d5251460af96d2e0311276f33
Parents: 8fea62b
Author: benoitc <bchesneau@gmail.com>
Authored: Tue Jul 1 22:58:11 2014 +0200
Committer: benoitc <bchesneau@gmail.com>
Committed: Tue Jul 1 22:58:11 2014 +0200

----------------------------------------------------------------------
 src/couch_mrview.erl | 30 +++++++++++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/91df48a1/src/couch_mrview.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview.erl b/src/couch_mrview.erl
index 6112cbd..a01d812 100644
--- a/src/couch_mrview.erl
+++ b/src/couch_mrview.erl
@@ -94,7 +94,7 @@ query_view(Db, {Type, View}, Args, Callback, Acc) ->
 view_changes_since(Db, DDoc, VName, StartSeq, Fun, Acc) ->
     view_changes_since(Db, DDoc, VName, StartSeq, Fun, [], Acc).
 
-view_changes_since(Db, DDoc, VName, StartSeq, Fun, Options, Acc) ->
+view_changes_since(Db, DDoc, VName, StartSeq, UserFun, Options, Acc) ->
     Args0 = make_view_changes_args(Options),
     {ok, {_, View}, _, Args} = couch_mrview_util:get_view(Db, DDoc, VName,
                                                           Args0),
@@ -105,9 +105,32 @@ view_changes_since(Db, DDoc, VName, StartSeq, Fun, Options, Acc) ->
                 true -> View#mrview.key_byseq_btree;
                 _ -> View#mrview.seq_btree
             end,
-            AccOut = lists:foldl(fun(Opts, Acc0) ->
+
+            %% wrap the function to make sure we only return the results
+            %% we want when we get changes for a key.
+            #mrargs{direction=Dir}=Args,
+            EndSeq = case Dir of
+                fwd -> 16#10000000;
+                rev -> 0
+            end,
+
+            WrapperFun = fun
+                ({{Seq, _Key, _DocId}, _Val}=KV, {fwd, LastSeq, Acc2})
+                        when Seq > LastSeq, Seq =< EndSeq ->
+                    {Go, Acc3} = UserFun(KV, Acc2),
+                    {Go, {fwd, Seq, Acc3}};
+                ({Seq, _Key, _DocId}=KV, {D, LastSeq, Acc2})
+                        when Seq < LastSeq, Seq >= EndSeq ->
+                    {Go, Acc3} = UserFun(KV, Acc2),
+                    {Go, {D, Seq, Acc3}};
+                (_, Acc2) ->
+                    {ok, Acc2}
+            end,
+
+            {_, _, AccOut} = lists:foldl(fun(Opts, Acc0) ->
+                        Acc1 = {Dir, StartSeq, Acc0},
                         {ok, _R, A} = couch_mrview_util:fold_changes(
-                                    Btree, Fun, Acc0, Opts),
+                                    Btree, WrapperFun, Acc1, Opts),
                         A
                 end, Acc, OptList),
             {ok, AccOut};
@@ -116,6 +139,7 @@ view_changes_since(Db, DDoc, VName, StartSeq, Fun, Options, Acc) ->
     end.
 
 
+
 count_view_changes_since(Db, DDoc, VName, SinceSeq) ->
     count_view_changes_since(Db, DDoc, VName, SinceSeq, []).
 


Mime
View raw message