couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [21/25] couch-mrview commit: updated refs/heads/1994-merge-rcouch to 7775266
Date Wed, 12 Feb 2014 23:29:16 GMT
couch_mrview: add API to retrieve view info.

Add couch_mrview:get_view_info/3 to retrieve the internal informations
of a view like the last update seq in this view or the number of rows.


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

Branch: refs/heads/1994-merge-rcouch
Commit: 916e1b3c902c52f2a98c20a0bc1800d76f11e91a
Parents: 96aa28d
Author: benoitc <benoitc@apache.org>
Authored: Sat Feb 8 22:49:42 2014 +0100
Committer: Paul J. Davis <paul.joseph.davis@gmail.com>
Committed: Wed Feb 12 17:27:40 2014 -0600

----------------------------------------------------------------------
 src/couch_mrview.erl | 25 +++++++++++++++++++++++++
 test/04-index-info.t | 10 +++++++++-
 2 files changed, 34 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/916e1b3c/src/couch_mrview.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview.erl b/src/couch_mrview.erl
index 26538a2..e5b0d99 100644
--- a/src/couch_mrview.erl
+++ b/src/couch_mrview.erl
@@ -17,6 +17,7 @@
 -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([get_view_info/3]).
 -export([refresh/2]).
 -export([compact/2, compact/3, cancel_compaction/2]).
 -export([cleanup/1]).
@@ -147,6 +148,30 @@ get_info(Db, DDoc) ->
     couch_index:get_info(Pid).
 
 
+%% get informations on a view
+get_view_info(Db, DDoc, VName) ->
+    {ok, {_, View}, _, _Args} = couch_mrview_util:get_view(Db, DDoc, VName,
+                                                          #mrargs{}),
+
+    %% get the total number of rows
+    {ok, TotalRows} =  couch_mrview_util:get_row_count(View),
+
+    %% get the total number of sequence logged in this view
+    SeqBtree = View#mrview.seq_btree,
+    {ok, TotalSeqs} = case SeqBtree of
+        nil -> {ok, 0};
+        _ ->
+            {ok, {Count, _Reds}} = couch_btree:full_reduce(SeqBtree),
+            {ok, Count}
+    end,
+
+    {ok, [{update_seq, View#mrview.update_seq},
+          {purge_seq, View#mrview.purge_seq},
+          {total_rows, TotalRows},
+          {total_seqs, TotalSeqs}]}.
+
+
+
 %% @doc refresh a view index
 refresh(#db{name=DbName}, DDoc) ->
     refresh(DbName, DDoc);

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/916e1b3c/test/04-index-info.t
----------------------------------------------------------------------
diff --git a/test/04-index-info.t b/test/04-index-info.t
index 34fb192..e95db1c 100644
--- a/test/04-index-info.t
+++ b/test/04-index-info.t
@@ -15,7 +15,7 @@
 % the License.
 
 main(_) ->
-    etap:plan(9),
+    etap:plan(12),
     case (catch test()) of
         ok ->
             etap:end_tests();
@@ -46,6 +46,14 @@ test() ->
     etap:is(getval(compact_running, Info), false, "No compaction running."),
     etap:is(getval(waiting_clients, Info), 0, "No waiting clients."),
 
+
+    {ok, ViewInfo} = couch_mrview:get_view_info(Db, <<"_design/bar">>,
+                                           <<"baz">>),
+    etap:is(getval(update_seq, ViewInfo), 11, "View Update seq is ok."),
+    etap:is(getval(purge_seq, ViewInfo), 0, "View Update seq is ok."),
+    etap:is(getval(total_rows, ViewInfo), 10, "View total rows is ok."),
+
+
     test_util:stop_couch(),
     ok.
 


Mime
View raw message