couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bbast...@apache.org
Subject [23/41] couch-mrview commit: updated refs/heads/master to 28e51f3
Date Fri, 31 Oct 2014 19:53:38 GMT
Add view filtering optimization to changes feeds. Remove unnecessary old stuff.


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

Branch: refs/heads/master
Commit: 24db15f39015bec4710da97789a1728523ce92e1
Parents: cc45433
Author: Benjamin Bastian <benjamin.bastian@gmail.com>
Authored: Fri Aug 22 23:57:48 2014 +0700
Committer: Benjamin Bastian <benjamin.bastian@gmail.com>
Committed: Thu Oct 30 13:38:35 2014 -0700

----------------------------------------------------------------------
 src/couch_mrview_changes.erl | 189 +-------------------------------------
 src/couch_mrview_http.erl    |   6 +-
 2 files changed, 2 insertions(+), 193 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/24db15f3/src/couch_mrview_changes.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_changes.erl b/src/couch_mrview_changes.erl
index cb55655..ae5aa6e 100644
--- a/src/couch_mrview_changes.erl
+++ b/src/couch_mrview_changes.erl
@@ -12,194 +12,7 @@
 %
 -module(couch_mrview_changes).
 
--export([handle_changes/6, handle_view_changes/5]).
-
--include_lib("couch/include/couch_db.hrl").
-
--record(vst, {dbname,
-              ddoc,
-              view,
-              view_options,
-              since,
-              callback,
-              acc,
-              user_timeout,
-              timeout,
-              heartbeat,
-              timeout_acc=0,
-              notifier,
-              stream,
-              refresh}).
-
--type changes_stream() :: true | false | once.
--type changes_options() :: [{stream, changes_stream()} |
-                            {since, integer()} |
-                            {view_options, list()} |
-                            {timeout, integer()} |
-                            {heartbeat, true | integer()} |
-                            {refresh, true | false}].
-
--export_type([changes_stream/0]).
--export_type([changes_options/0]).
+-export([handle_view_changes/5]).
 
 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()}.
-handle_changes(DbName, DDocId, View, Fun, Acc, Options) ->
-    Since = proplists:get_value(since, Options, 0),
-    Stream = proplists:get_value(stream, Options, false),
-    ViewOptions = proplists:get_value(view_options, Options, []),
-    Refresh = proplists:get_value(refresh, Options, false),
-
-    State0 = #vst{dbname=DbName,
-                  ddoc=DDocId,
-                  view=View,
-                  view_options=ViewOptions,
-                  since=Since,
-                  callback=Fun,
-                  acc=Acc},
-
-    maybe_acquire_indexer(Refresh, DbName, DDocId),
-    try
-        case view_changes_since(State0) of
-            {ok, #vst{since=LastSeq, acc=Acc2}=State} ->
-                case Stream of
-                    true ->
-                        start_loop(State#vst{stream=true}, Options);
-                    once when LastSeq =:= Since ->
-                        start_loop(State#vst{stream=once}, Options);
-                    _ ->
-                        Fun(stop, {LastSeq, Acc2})
-                end;
-            {stop, #vst{since=LastSeq, acc=Acc2}} ->
-                Fun(stop, {LastSeq, Acc2});
-            Error ->
-                Error
-        end
-    after
-        maybe_release_indexer(Refresh, DbName, DDocId)
-    end.
-
-start_loop(#vst{dbname=DbName, ddoc=DDocId}=State, Options) ->
-    {UserTimeout, Timeout, Heartbeat} = changes_timeout(Options),
-    Notifier = index_update_notifier(DbName, DDocId),
-    try
-        loop(State#vst{notifier=Notifier,
-                       user_timeout=UserTimeout,
-                       timeout=Timeout,
-                       heartbeat=Heartbeat})
-    after
-        couch_index_event:stop(Notifier)
-    end.
-
-loop(#vst{since=Since, callback=Callback, acc=Acc,
-          user_timeout=UserTimeout, timeout=Timeout,
-          heartbeat=Heartbeat, timeout_acc=TimeoutAcc,
-          stream=Stream}=State) ->
-    receive
-        index_update ->
-            case view_changes_since(State) of
-                {ok, State2} when Stream =:= true ->
-                    loop(State2#vst{timeout_acc=0});
-                {ok, #vst{since=LastSeq, acc=Acc2}} ->
-                    Callback(stop, {LastSeq, Acc2});
-                {stop, #vst{since=LastSeq, acc=Acc2}} ->
-                    Callback(stop, {LastSeq, Acc2})
-            end;
-        index_delete ->
-            Callback(stop, {Since, Acc})
-    after Timeout ->
-            TimeoutAcc2 = TimeoutAcc + Timeout,
-            case UserTimeout =< TimeoutAcc2 of
-                true ->
-                    Callback(stop, {Since, Acc});
-                false when Heartbeat =:= true ->
-                    case Callback(heartbeat, Acc) of
-                        {ok, Acc2} ->
-                            loop(State#vst{acc=Acc2, timeout_acc=TimeoutAcc2});
-                        {stop, Acc2} ->
-                            Callback(stop, {Since, Acc2})
-                    end;
-                _ ->
-                    Callback(stop, {Since, Acc})
-            end
-    end.
-
-changes_timeout(Options) ->
-    DefaultTimeout = list_to_integer(
-            couch_config:get("httpd", "changes_timeout", "60000")
-    ),
-    UserTimeout = proplists:get_value(timeout, Options, DefaultTimeout),
-    {Timeout, Heartbeat} = case proplists:get_value(heartbeat, Options) of
-        undefined -> {UserTimeout, false};
-        true ->
-            T = erlang:min(DefaultTimeout, UserTimeout),
-            {T, true};
-        H ->
-            T = erlang:min(H, UserTimeout),
-            {T, true}
-    end,
-    {UserTimeout, Timeout, Heartbeat}.
-
-view_changes_since(#vst{dbname=DbName, ddoc=DDocId, view=View,
-                        view_options=Options, since=Since,
-                        callback=Callback, acc=UserAcc}=State) ->
-    Wrapper = fun ({{Seq, _Key, _DocId}, _Val}=KV, {_Go, Acc2, OldSeq}) ->
-            LastSeq = if OldSeq < Seq -> Seq;
-                true -> OldSeq
-            end,
-
-            {Go, Acc3} = Callback(KV, Acc2),
-            {Go, {Go, Acc3, LastSeq}}
-    end,
-
-    Acc0 = {ok, UserAcc, Since},
-    case couch_mrview:view_changes_since(DbName, DDocId, View, Since,
-                                         Wrapper, Options, Acc0) of
-        {ok, {Go, UserAcc2, Since2}}->
-            {Go, State#vst{since=Since2, acc=UserAcc2}};
-        Error ->
-            Error
-    end.
-
-index_update_notifier(#db{name=DbName}, DDocId) ->
-    index_update_notifier(DbName, DDocId);
-index_update_notifier(DbName, DDocId) ->
-    Self = self(),
-    {ok, NotifierPid} = couch_index_event:start_link(fun
-                ({index_update, {Name, Id, couch_mrview_index}})
-                        when Name =:= DbName, Id =:= DDocId ->
-                    Self ! index_update;
-                ({index_delete, {Name, Id, couch_mrview_index}})
-                        when Name =:= DbName, Id =:= DDocId ->
-                    Self ! index_delete;
-                (_) ->
-                    ok
-            end),
-    NotifierPid.
-
-%% acquire the background indexing task so it can eventually be started
-%% if the process close the background task will be automatically
-%% released.
-maybe_acquire_indexer(false, _, _) ->
-    ok;
-maybe_acquire_indexer(true, DbName, DDocId) ->
-    couch_index_server:acquire_indexer(couch_mrview_index, DbName,
-                                       DDocId).
-
-%% release the background indexing task so it can eventually be stopped
-maybe_release_indexer(false, _, _) ->
-    ok;
-maybe_release_indexer(true, DbName, DDocId) ->
-    couch_index_server:release_indexer(couch_mrview_index, DbName,
-                                       DDocId).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/24db15f3/src/couch_mrview_http.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview_http.erl b/src/couch_mrview_http.erl
index 2b396b0..bb49583 100644
--- a/src/couch_mrview_http.erl
+++ b/src/couch_mrview_http.erl
@@ -36,10 +36,6 @@
     check_view_etag/3
 ]).
 
--export([parse_boolean/1,
-         parse_int/1,
-         parse_pos_int/1]).
-
 -include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_mrview/include/couch_mrview.hrl").
 
@@ -76,7 +72,7 @@ handle_view_changes_req(#httpd{path_parts=[_,<<"_design">>,DDocName,<<"_view_cha
             throw({bad_request, "view changes not enabled"})
     end,
 
-    ChangesArgs = couch_httpd_changes:parse_changes_query(Req, Db, true),
+    ChangesArgs = couch_httpd_changes:parse_changes_query(Req, Db),
     ChangesFun = couch_mrview_changes:handle_view_changes(ChangesArgs, Req, Db, <<"_design/",
DDocName/binary>>, ViewName),
     couch_httpd_changes:handle_changes_req(Req, Db, ChangesArgs, ChangesFun).
 


Mime
View raw message