Use ddoc_to_mrst instead of trying to load the local view This fixes a problem where loading the view locally assumes that the database is actually on the node in question, which is not a safe assumption to make. This takes the ddoc and passes it through ddoc_to_mrst which will allow us to do validation on the request and also to determine whether or not the given view queried is a reduce view.
Project: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/commit/fa73a5dc Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/tree/fa73a5dc Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fabric/diff/fa73a5dc Branch: refs/heads/1993-bigcouch-couch-mrview Commit: fa73a5dc5290be5d921c0fbaf1a144930f56bca8 Parents: 3eab4d6 Author: Russell Branca <[email protected]> Authored: Tue Mar 11 13:10:34 2014 -0400 Committer: Russell Branca <[email protected]> Committed: Tue Mar 11 13:10:34 2014 -0400 ---------------------------------------------------------------------- src/fabric.erl | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-fabric/blob/fa73a5dc/src/fabric.erl ---------------------------------------------------------------------- diff --git a/src/fabric.erl b/src/fabric.erl index 24bd9b8..5be6f49 100644 --- a/src/fabric.erl +++ b/src/fabric.erl @@ -280,23 +280,20 @@ query_view(DbName, DesignName, ViewName, QueryArgs) -> any(). query_view(DbName, GroupId, ViewName, Callback, Acc0, QueryArgs) when is_binary(GroupId) -> - {ok, DDoc} = fabric:open_doc(DbName, <<"_design/", GroupId/binary>>, []), + {ok, DDoc} = ddoc_cache:open(DbName, <<"_design/", GroupId/binary>>), query_view(DbName, DDoc, ViewName, Callback, Acc0, QueryArgs); -query_view(DbName, Design, ViewName, Callback, Acc0, QueryArgs0) -> +query_view(DbName, DDoc, ViewName, Callback, Acc0, QueryArgs0) -> Db = dbname(DbName), View = name(ViewName), - {VInfo, QueryArgs2} = couch_util:with_db( - Db, - fun(WDb) -> - {ok, VInfo0, _Sig, QueryArgs1} = - couch_mrview_util:get_view(WDb, Design, ViewName, QueryArgs0), - {VInfo0, QueryArgs1} - end - ), - case is_reduce_view(VInfo) of + {ok, #mrst{views=Views, language=Lang}} = + couch_mrview_util:ddoc_to_mrst(Db, DDoc), + QueryArgs1 = couch_mrview_util:set_view_type(QueryArgs0, View, Views), + QueryArgs2 = couch_mrview_util:validate_args(QueryArgs1), + VInfo = couch_mrview_util:extract_view(Lang, QueryArgs2, View, Views), + case is_reduce_view(QueryArgs2) of true -> fabric_view_reduce:go( Db, - Design, + DDoc, View, QueryArgs2, Callback, @@ -304,7 +301,7 @@ query_view(DbName, Design, ViewName, Callback, Acc0, QueryArgs0) -> VInfo ); false -> - fabric_view_map:go(Db, Design, View, QueryArgs2, Callback, Acc0) + fabric_view_map:go(Db, DDoc, View, QueryArgs2, Callback, Acc0) end. %% @doc retrieve info about a view group, disk size, language, whether compaction @@ -456,6 +453,8 @@ default_callback(complete, Acc) -> default_callback(Row, Acc) -> {ok, [Row | Acc]}. +is_reduce_view(#mrargs{view_type=ViewType}) -> + ViewType =:= red; is_reduce_view({Reduce, _, _}) -> Reduce =:= red.
