summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbenoitc <benoitc@apache.org>2014-02-08 22:49:42 +0100
committerbenoitc <benoitc@apache.org>2014-02-08 22:49:42 +0100
commit1e6114c56da5f7592718a7eecb6adfd5b56fc3e2 (patch)
treebccb7c52dd1368f4e631240f4ec1ee4f49108765
parent4357ef76bde008bc86c5d39b7b94e6a284b330fa (diff)
downloadcouchdb-1e6114c56da5f7592718a7eecb6adfd5b56fc3e2.tar.gz
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.
-rw-r--r--apps/couch_mrview/src/couch_mrview.erl25
-rw-r--r--apps/couch_mrview/test/04-index-info.t10
2 files changed, 34 insertions, 1 deletions
diff --git a/apps/couch_mrview/src/couch_mrview.erl b/apps/couch_mrview/src/couch_mrview.erl
index 26538a251..e5b0d9958 100644
--- a/apps/couch_mrview/src/couch_mrview.erl
+++ b/apps/couch_mrview/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);
diff --git a/apps/couch_mrview/test/04-index-info.t b/apps/couch_mrview/test/04-index-info.t
index 34fb192be..e95db1ccb 100644
--- a/apps/couch_mrview/test/04-index-info.t
+++ b/apps/couch_mrview/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.