couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bbast...@apache.org
Subject [21/41] couch-mrview commit: updated refs/heads/master to 28e51f3
Date Fri, 31 Oct 2014 19:53:36 GMT
Add preliminary version of view changes


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

Branch: refs/heads/master
Commit: 062c1e7fc9b0cb96f7a95b2b218d4a473db809e4
Parents: 45da4bc
Author: Benjamin Bastian <benjamin.bastian@gmail.com>
Authored: Fri Aug 22 15:52:31 2014 +0700
Committer: Benjamin Bastian <benjamin.bastian@gmail.com>
Committed: Thu Oct 30 13:38:34 2014 -0700

----------------------------------------------------------------------
 src/couch_mrview.erl         | 21 +++++++++++++++------
 src/couch_mrview_changes.erl | 12 +++++++++++-
 src/couch_mrview_http.erl    |  7 +++++++
 3 files changed, 33 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/062c1e7f/src/couch_mrview.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview.erl b/src/couch_mrview.erl
index 4658781..c6e413b 100644
--- a/src/couch_mrview.erl
+++ b/src/couch_mrview.erl
@@ -15,6 +15,7 @@
 -export([validate/2]).
 -export([query_all_docs/2, query_all_docs/4]).
 -export([query_view/3, query_view/4, query_view/6]).
+-export([view_changes_since/5]).
 -export([view_changes_since/6, view_changes_since/7]).
 -export([count_view_changes_since/4, count_view_changes_since/5]).
 -export([get_info/2]).
@@ -139,13 +140,21 @@ query_view(Db, {Type, View, Ref}, Args, Callback, Acc) ->
         erlang:demonitor(Ref, [flush])
     end.
 
+view_changes_since(View, StartSeq, Fun, Opts0, Acc) ->
+    Wrapper = fun(KV, _, Acc1) ->
+        Fun(KV, Acc1)
+    end,
+    Opts = [{start_key, {StartSeq + 1, <<>>}}] ++ Opts0,
+    {ok, _LastRed, AccOut} = couch_btree:fold(View#mrview.seq_btree, Wrapper, Acc, Opts),
+    {ok, AccOut}.
+
 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) ->
     Args0 = make_view_changes_args(Options),
-    {ok, {_, View}, _, Args} = couch_mrview_util:get_view(Db, DDoc, VName,
-                                                          Args0),
+    {ok, {_, View, _}, _, Args} = couch_mrview_util:get_view(Db, DDoc, VName,
+                                                             Args0),
     case View#mrview.seq_indexed of
         true ->
             OptList = make_view_changes_opts(StartSeq, Options, Args),
@@ -154,10 +163,10 @@ view_changes_since(Db, DDoc, VName, StartSeq, Fun, Options, Acc) ->
                 _ -> View#mrview.seq_btree
             end,
             AccOut = lists:foldl(fun(Opts, Acc0) ->
-                        {ok, _R, A} = couch_mrview_util:fold_changes(
-                                    Btree, Fun, Acc0, Opts),
-                        A
-                end, Acc, OptList),
+                {ok, _R, A} = couch_mrview_util:fold_changes(
+                    Btree, Fun, Acc0, Opts),
+                A
+            end, Acc, OptList),
             {ok, AccOut};
         _ ->
             {error, seqs_not_indexed}

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/062c1e7f/src/couch_mrview_changes.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_changes.erl b/src/couch_mrview_changes.erl
index 735ded8..cb55655 100644
--- a/src/couch_mrview_changes.erl
+++ b/src/couch_mrview_changes.erl
@@ -12,7 +12,7 @@
 %
 -module(couch_mrview_changes).
 
--export([handle_changes/6]).
+-export([handle_changes/6, handle_view_changes/5]).
 
 -include_lib("couch/include/couch_db.hrl").
 
@@ -42,6 +42,16 @@
 -export_type([changes_stream/0]).
 -export_type([changes_options/0]).
 
+handle_view_changes(Args, Req, Db, DDocId, ViewName) ->
+%    couch_index_server:acquire_indexer(couch_mrview_index, Db#db.name, DDocId),
+%    try
+    couch_changes:handle_changes(Args, Req, Db, {view, DDocId, ViewName}).
+%    after
+%        couch_index_server:release_indexer(couch_mrview_index, Db#db.name, DDocId)
+%    end.
+
+
+
 %% @doc function returning changes in a streaming fashion if needed.
 -spec handle_changes(binary(), binary(), binary(), function(), term(),
                      changes_options()) -> ok | {error, term()}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/062c1e7f/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 7a4c13c..1e54195 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -14,6 +14,7 @@
 
 -export([
     handle_all_docs_req/2,
+    handle_view_changes_req/3,
     handle_reindex_req/3,
     handle_view_req/3,
     handle_temp_view_req/2,
@@ -61,6 +62,12 @@ handle_reindex_req(Req, _Db, _DDoc) ->
     couch_httpd:send_method_not_allowed(Req, "POST").
 
 
+handle_view_changes_req(#httpd{path_parts=[_,<<"_design">>,DDocName,<<"_view_changes">>,ViewName]}=Req,
Db, _DDoc) ->
+    ChangesArgs = couch_httpd_changes:parse_changes_query(Req, Db, true),
+    ChangesFun = couch_mrview_changes:handle_view_changes(ChangesArgs, Req, Db, DDocName,
ViewName),
+    couch_httpd_changes:handle_changes_req(Req, Db, ChangesArgs, ChangesFun).
+
+
 handle_view_req(#httpd{method='GET',
                       path_parts=[_, _, DDocName, _, VName, <<"_info">>]}=Req,
                 Db, _DDoc) ->


Mime
View raw message