couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [04/25] couch-mrview commit: updated refs/heads/1994-merge-rcouch to 7775266
Date Wed, 12 Feb 2014 23:28:59 GMT
couch_mrview: add couch_mrview:count_view_changes_since/{4,5}

Add function to couch changes in a view index, similar to
couch_db:count_changes_since/2 .


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/188b30f7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/188b30f7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/188b30f7

Branch: refs/heads/1994-merge-rcouch
Commit: 188b30f7f2289613350dca67b8c8b71c0a58f518
Parents: 26d16a6
Author: benoitc <benoitc@apache.org>
Authored: Mon Jan 27 11:51:11 2014 +0100
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Wed Feb 12 17:27:39 2014 -0600

----------------------------------------------------------------------
 src/couch_mrview.erl      | 30 ++++++++++++++++++++++++++++++
 src/couch_mrview_util.erl |  8 ++++++--
 2 files changed, 36 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/188b30f7/src/couch_mrview.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview.erl b/src/couch_mrview.erl
index eb929a6..d8f092c 100644
--- a/src/couch_mrview.erl
+++ b/src/couch_mrview.erl
@@ -15,6 +15,7 @@
 -export([query_all_docs/2, query_all_docs/4]).
 -export([query_view/3, query_view/4, query_view/6]).
 -export([view_changes_since/6, view_changes_since/7]).
+-export([count_view_changes_since/4, count_view_changes_since/5]).
 -export([get_info/2]).
 -export([compact/2, compact/3, cancel_compaction/2]).
 -export([cleanup/1]).
@@ -111,6 +112,35 @@ view_changes_since(Db, DDoc, VName, StartSeq, Fun, Options, Acc) ->
             {error, seqs_not_indexed}
     end.
 
+
+count_view_changes_since(Db, DDoc, VName, SinceSeq) ->
+    count_view_changes_since(Db, DDoc, VName, SinceSeq, []).
+
+count_view_changes_since(Db, DDoc, VName, SinceSeq, Options) ->
+    Args0 = make_view_changes_args(Options),
+    {ok, {_, View}, _, Args} = couch_mrview_util:get_view(Db, DDoc, VName,
+                                                          Args0),
+    case View#mrview.seq_indexed of
+        true ->
+            OptList = make_view_changes_opts(SinceSeq, Options, Args),
+            Btree = case is_key_byseq(Options) of
+                true -> View#mrview.key_byseq_btree;
+                _ -> View#mrview.seq_btree
+            end,
+            lists:foldl(fun(Opts, Acc0) ->
+                            {ok, N} = couch_btree:fold_reduce(
+                                    Btree, fun(_SeqStart, PartialReds, 0) ->
+                                        {ok, couch_btree:final_reduce(
+                                                    Btree, PartialReds)}
+                                    end,
+                                0, Opts),
+                            Acc0 + N
+                    end, 0, OptList);
+        _ ->
+            {error, seqs_not_indexed}
+    end.
+
+
 get_info(Db, DDoc) ->
     {ok, Pid} = couch_index_server:get_index(couch_mrview_index, Db, DDoc),
     couch_index:get_info(Pid).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/188b30f7/src/couch_mrview_util.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_util.erl b/src/couch_mrview_util.erl
index 673265a..8cb4fae 100644
--- a/src/couch_mrview_util.erl
+++ b/src/couch_mrview_util.erl
@@ -236,7 +236,6 @@ less_json_seqs({SeqA, JsonA}, {SeqB, JsonB}) ->
             Result < 0
     end.
 
-
 open_view(Db, Fd, Lang, {BTState, SeqBTState, KSeqBTState, USeq, PSeq}, View) ->
     FunSrcs = [FunSrc || {_Name, FunSrc} <- View#mrview.reduce_funs],
     ReduceFun =
@@ -265,10 +264,15 @@ open_view(Db, Fd, Lang, {BTState, SeqBTState, KSeqBTState, USeq, PSeq},
View) ->
 
     {SeqBtree, KeyBySeqBtree} = case View#mrview.seq_indexed of
         true ->
+            BySeqReduceFun = fun couch_db_updater:btree_by_seq_reduce/2,
             ViewSeqBtOpts = [{less, fun less_json_seqs/2},
+                             {reduce, BySeqReduceFun},
                              {compression, couch_db:compression(Db)}],
+            KeyBySeqBtOpts = [{less, Less},
+                              {reduce, BySeqReduceFun},
+                              {compression, couch_db:compression(Db)}],
             {ok, SBt} = couch_btree:open(SeqBTState, Fd, ViewSeqBtOpts),
-            {ok, KSBt} = couch_btree:open(KSeqBTState, Fd, ViewBtOpts),
+            {ok, KSBt} = couch_btree:open(KSeqBTState, Fd, KeyBySeqBtOpts),
             {SBt, KSBt};
         false ->
             {nil, nil}


Mime
View raw message