This is an automated email from the ASF dual-hosted git repository. davisp pushed a commit to branch prototype/views in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit d0cfb019ee44d2015511fadd6e12698536cb4221 Author: Paul J. Davis <[email protected]> AuthorDate: Tue Jul 16 15:12:27 2019 -0500 Don't add a fabric2_view module There was barely any logic contained there that's easily included in the couch_views module. Its mostly historical that fabric includes all of the view logic anyway. Now that we have multiple indexers it's more hygenic to move all the code to a single application. For the chttpd level I'm going to leave the logic in chttpd_view.erl for the time being. When we go to clean up code in terms of deleting unused code and moving used code out of mostly deleted applications. --- src/couch_views/src/couch_views.erl | 101 +++++++++++++++++++++++++++--------- src/fabric/src/fabric2_view.erl | 81 ----------------------------- 2 files changed, 76 insertions(+), 106 deletions(-) diff --git a/src/couch_views/src/couch_views.erl b/src/couch_views/src/couch_views.erl index 69d6765..c059204 100644 --- a/src/couch_views/src/couch_views.erl +++ b/src/couch_views/src/couch_views.erl @@ -13,41 +13,48 @@ -module(couch_views). -export([ - map_query/6 + query/6 ]). --include("couch_views.hrl"). +-include("couch_mrview/include/couch_mrview.hrl"). -map_query(Db, DDoc, ViewName, Callback, Acc0, Args0) -> - Args = process_args(Args0), - #{name := DbName} = Db, - {ok, Mrst} = couch_views_util:ddoc_to_mrst(DbName, DDoc), - maybe_build_index(Db, Mrst, Args), - Resp = couch_views_reader:read(Db, DDoc, ViewName, Callback, Acc0, Args), - - UpdateAfter = maps:get(update, Args) == lazy, - if UpdateAfter == false -> ok; true -> - maybe_add_couch_job(Db, Mrst) +query(Db, DDoc, ViewName, Callback, Acc0, QueryArgs0) -> + case fabric2_db:is_users_db(Db) of + true -> + fabric2_users_db:after_doc_read(DDoc, Db); + false -> + ok end, - Resp. + DbName = fabric2_db:name(Db), + {ok, Mrst} = couch_views_util:ddoc_to_mrst(DbName, DDoc), -process_args(#{} = Args) -> - Args1 = remove_ununsed_values(Args), - Defaults = #{ - direction => fwd, - inclusive_end => true, - update => true, - skip => 0, - limit => ?MAX_VIEW_LIMIT - }, + #mrst{ + views = Views, + language = Lang + } = Mrst, + + 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 -> throw({not_implemented}); + false -> ok + end, - maps:merge(Defaults, Args1). + Args = mrargs_to_map(QueryArgs2), + maybe_build_view(Db, MrSt, Args), -remove_ununsed_values(Args) -> - maps:filter(fun (_, V) -> V /= undefined end, Args). + try + couch_views_reader:read(Db, Mrst, ViewName, Callback, Acc0, Args) + after + UpdateAfter = maps:get(update, Args) == lazy, + if UpdateAfter == false -> ok; true -> + maybe_add_couch_job(Db, Mrst) + end + end. maybe_build_index(_Db, _Mrst, #{update := false}) -> @@ -118,3 +125,47 @@ wait_for_index_ready(Subscription, Db, Mrst, Seq) -> {error, Error} -> throw({error, Error}) end. + + +is_reduce_view(#mrargs{view_type = ViewType}) -> + ViewType =:= red; +is_reduce_view({Reduce, _, _}) -> + Reduce =:= red. + + +mrargs_to_map(#mrargs{} = Args) -> + process_args(#{ + start_key => Args#mrargs.start_key, + start_key_docid => Args#mrargs.start_key_docid, + end_key => Args#mrargs.end_key, + end_key_docid => Args#mrargs.end_key_docid, + keys => Args#mrargs.keys, + direction => Args#mrargs.direction, + limit => Args#mrargs.limit, + skip => Args#mrargs.skip, + update => Args#mrargs.update, + multi_get => Args#mrargs.multi_get, + inclusive_end => Args#mrargs.inclusive_end, + include_docs => Args#mrargs.include_docs, + doc_options => Args#mrargs.doc_options, + update_seq => Args#mrargs.update_seq, + conflicts => Args#mrargs.conflicts, + sorted => Args#mrargs.sorted + }). + + +process_args(#{} = Args) -> + Args1 = remove_ununsed_values(Args), + Defaults = #{ + direction => fwd, + inclusive_end => true, + update => true, + skip => 0, + limit => ?MAX_VIEW_LIMIT + }, + + maps:merge(Defaults, Args1). + + +remove_ununsed_values(Args) -> + maps:filter(fun (_, V) -> V /= undefined end, Args). diff --git a/src/fabric/src/fabric2_view.erl b/src/fabric/src/fabric2_view.erl deleted file mode 100644 index 01c9ab0..0000000 --- a/src/fabric/src/fabric2_view.erl +++ /dev/null @@ -1,81 +0,0 @@ -% Licensed under the Apache License, Version 2.0 (the "License"); you may not -% use this file except in compliance with the License. You may obtain a copy of -% the License at -% -% http://www.apache.org/licenses/LICENSE-2.0 -% -% Unless required by applicable law or agreed to in writing, software -% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT -% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the -% License for the specific language governing permissions and limitations under -% the License. - --module(fabric2_view). - --export([ - query/7 -]). - --include_lib("couch_mrview/include/couch_mrview.hrl"). - -%% @doc execute a given view. -%% There are many additional query args that can be passed to a view, -%% see <a href="http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options"> -%% query args</a> for details. -% -spec query(db(), [{atom(), any()}] | [], -% #doc{} | binary(), iodata(), callback(), any(), #mrargs{}) -> any(). -query(Db, Options, DDoc, ViewName, Callback, Acc0, QueryArgs0) -> - DbName = fabric2_db:name(Db), -%% View = name(ViewName), - case fabric_util:is_users_db(DbName) of - true -> - FakeDb = fabric_util:open_cluster_db(DbName, Options), - couch_users_db:after_doc_read(DDoc, FakeDb); - false -> - ok - end, -%% {ok, #mrst{views=Views, language=Lang}} = -%% couch_views_util:ddoc_to_mrst(DbName, DDoc), -%% QueryArgs1 = couch_mrview_util:set_view_type(QueryArgs0, View, Views), -%% QueryArgs1 = fabric_util:validate_args(Db, DDoc, QueryArgs0), - QueryArgs1 = couch_mrview_util:validate_args(Db, DDoc, QueryArgs0), -%% VInfo = couch_mrview_util:extract_view(Lang, QueryArgs1, View, Views), - case is_reduce_view(QueryArgs1) of - true -> - throw({not_implemented}); - false -> - MapQueryArgs = mrargs_to_map((QueryArgs1)), - couch_views:map_query(Db, DDoc, ViewName, Callback, - Acc0, MapQueryArgs) - end. - - -is_reduce_view(_) -> - false. - - -name(Thing) -> - couch_util:to_binary(Thing). - - -mrargs_to_map(#mrargs{} = Args) -> - #{ - start_key => Args#mrargs.start_key, - start_key_docid => Args#mrargs.start_key_docid, - end_key => Args#mrargs.end_key, - end_key_docid => Args#mrargs.end_key_docid, - keys => Args#mrargs.keys, - direction => Args#mrargs.direction, - limit => Args#mrargs.limit, - skip => Args#mrargs.skip, - update => Args#mrargs.update, - multi_get => Args#mrargs.multi_get, - inclusive_end => Args#mrargs.inclusive_end, - include_docs => Args#mrargs.include_docs, - doc_options => Args#mrargs.doc_options, - update_seq => Args#mrargs.update_seq, - conflicts => Args#mrargs.conflicts, - sorted => Args#mrargs.sorted - }. - -
