You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2016/02/25 21:03:14 UTC
[12/12] couch commit: updated
refs/heads/2938-fix-5986-filtered-changes to 9171d5a
Conditionally use fetch and ddoc_cache logic
Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/9171d5a8
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/9171d5a8
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/9171d5a8
Branch: refs/heads/2938-fix-5986-filtered-changes
Commit: 9171d5a8f043f7108c148c2a495ed1a4514b1510
Parents: 9383c5c
Author: Russell Branca <ch...@apache.org>
Authored: Thu Feb 25 19:47:13 2016 +0000
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Feb 25 20:02:31 2016 +0000
----------------------------------------------------------------------
src/couch_changes.erl | 42 ++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/9171d5a8/src/couch_changes.erl
----------------------------------------------------------------------
diff --git a/src/couch_changes.erl b/src/couch_changes.erl
index 73a3cce..325fbac 100644
--- a/src/couch_changes.erl
+++ b/src/couch_changes.erl
@@ -21,6 +21,7 @@
wait_updated/3,
get_rest_updated/1,
configure_filter/4,
+ configure_filter/5,
filter/3,
handle_db_event/3,
handle_view_event/3,
@@ -194,11 +195,15 @@ get_callback_acc(Callback) when is_function(Callback, 2) ->
{fun(Ev, Data, _) -> Callback(Ev, Data) end, ok}.
-configure_filter("_doc_ids", Style, Req, _Db) ->
+configure_filter(Filter, Style, Req, Db) ->
+ configure_filter(Filter, Style, Req, Db, false).
+
+
+configure_filter("_doc_ids", Style, Req, _Db, _) ->
{doc_ids, Style, get_doc_ids(Req)};
-configure_filter("_design", Style, _Req, _Db) ->
+configure_filter("_design", Style, _Req, _Db, _) ->
{design_docs, Style};
-configure_filter("_view", Style, Req, Db) ->
+configure_filter("_view", Style, Req, Db, _) ->
ViewName = get_view_qs(Req),
if ViewName /= "" -> ok; true ->
throw({bad_request, "`view` filter parameter is not provided."})
@@ -221,21 +226,25 @@ configure_filter("_view", Style, Req, Db) ->
Msg = "`view` must be of the form `designname/viewname`",
throw({bad_request, Msg})
end;
-configure_filter([$_ | _], _Style, _Req, _Db) ->
+configure_filter([$_ | _], _Style, _Req, _Db, _) ->
throw({bad_request, "unknown builtin filter name"});
-configure_filter("", main_only, _Req, _Db) ->
+configure_filter("", main_only, _Req, _Db, _) ->
{default, main_only};
-configure_filter("", all_docs, _Req, _Db) ->
+configure_filter("", all_docs, _Req, _Db, _) ->
{default, all_docs};
-configure_filter(FilterName, Style, Req, Db) ->
+configure_filter(FilterName, Style, Req, Db, UseFetch) ->
FilterNameParts = string:tokens(FilterName, "/"),
case [?l2b(couch_httpd:unquote(Part)) || Part <- FilterNameParts] of
[DName, FName] ->
- DesignId = <<"_design/", DName/binary>>,
- {ok, DDoc} = ddoc_cache:open_doc(fabric:dbname(Db), DesignId),
+ {ok, DDoc} = open_ddoc(Db, <<"_design/", DName/binary>>),
check_member_exists(DDoc, [<<"filters">>, FName]),
- DIR = fabric_util:doc_id_and_rev(DDoc),
- {fetch, Style, Req, DIR, FName};
+ case UseFetch of
+ true ->
+ DIR = fabric_util:doc_id_and_rev(DDoc),
+ {fetch, Style, Req, DIR, FName};
+ _ ->
+ {custom, Style, Req, DDoc, FName}
+ end;
[] ->
{default, Style};
@@ -339,15 +348,8 @@ check_docids(_) ->
open_ddoc(#db{name=DbName, id_tree=undefined}, DDocId) ->
- {_, Ref} = spawn_monitor(fun() ->
- exit(fabric:open_doc(mem3:dbname(DbName), DDocId, [ejson_body]))
- end),
- receive
- {'DOWN', Ref, _, _, {ok, _}=Response} ->
- Response;
- {'DOWN', Ref, _, _, Response} ->
- throw(Response)
- end;
+ {ok, DDoc} = ddoc_cache:open_doc(mem3:dbname(DbName), DDocId),
+ {ok, DDoc};
open_ddoc(Db, DDocId) ->
case couch_db:open_doc(Db, DDocId, [ejson_body]) of
{ok, _} = Resp -> Resp;