Skip to content

Commit

Permalink
chore(access): erlfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
janl committed Aug 20, 2022
1 parent 6199ccd commit c4d4373
Show file tree
Hide file tree
Showing 19 changed files with 1,224 additions and 735 deletions.
11 changes: 4 additions & 7 deletions src/chttpd/src/chttpd_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ db_doc_req(#httpd{method = 'DELETE'} = Req, Db, DocId) ->
Rev ->
Body = {[{<<"_rev">>, ?l2b(Rev)}, {<<"_deleted">>, true}]}
end,
Doc = #doc{revs=Revs,body=Body,deleted=true,access=Doc0#doc.access},
Doc = #doc{revs = Revs, body = Body, deleted = true, access = Doc0#doc.access},
send_updated_doc(Req, Db, DocId, couch_doc_from_req(Req, Db, DocId, Doc));
db_doc_req(#httpd{method = 'GET', mochi_req = MochiReq} = Req, Db, DocId) ->
#doc_query_args{
Expand Down Expand Up @@ -1498,7 +1498,7 @@ receive_request_data(Req, LenLeft) when LenLeft > 0 ->
receive_request_data(_Req, _) ->
throw(<<"expected more data">>).

update_doc_result_to_json({#doc{id=Id,revs=Rev}, access}) ->
update_doc_result_to_json({#doc{id = Id, revs = Rev}, access}) ->
update_doc_result_to_json({{Id, Rev}, access});
update_doc_result_to_json({error, _} = Error) ->
{_Code, Err, Msg} = chttpd:error_info(Error),
Expand Down Expand Up @@ -2083,13 +2083,12 @@ parse_shards_opt("placement", Req, Default) ->
throw({bad_request, Err})
end
end;


parse_shards_opt("access", Req, Value) when is_list(Value) ->
parse_shards_opt("access", Req, list_to_existing_atom(Value));
parse_shards_opt("access", _Req, Value) when Value =:= true ->
case config:get_boolean("per_doc_access", "enabled", false) of
true -> true;
true ->
true;
false ->
Err = ?l2b(["The `access` option is not available on this CouchDB installation."]),
throw({bad_request, Err})
Expand All @@ -2099,7 +2098,6 @@ parse_shards_opt("access", _Req, Value) when Value =:= false ->
parse_shards_opt("access", _Req, _Value) ->
Err = ?l2b(["The `access` value should be a boolean."]),
throw({bad_request, Err});

parse_shards_opt(Param, Req, Default) ->
couch_log:error("~n parse_shards_opt Param: ~p, Default: ~p~n", [Param, Default]),
Val = chttpd:qs_value(Req, Param, Default),
Expand All @@ -2109,7 +2107,6 @@ parse_shards_opt(Param, Req, Default) ->
false -> throw({bad_request, Err})
end.


parse_engine_opt(Req) ->
case chttpd:qs_value(Req, "engine") of
undefined ->
Expand Down
28 changes: 14 additions & 14 deletions src/chttpd/src/chttpd_view.erl
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,20 @@ fabric_query_view(Db, Req, DDoc, ViewName, Args) ->
Max = chttpd:chunked_response_buffer_size(),
VAcc = #vacc{db = Db, req = Req, threshold = Max},
Options = [{user_ctx, Req#httpd.user_ctx}],
% {ok, Resp} = fabric:query_view(Db, Options, DDoc, ViewName,
% fun view_cb/2, VAcc, Args),
% {ok, Resp#vacc.resp}.
% % TODO: This might just be a debugging leftover, we might be able
% % to undo this by just returning {ok, Resp#vacc.resp}
% % However, this *might* be here because we need to handle
% % errors here now, because access might tell us to.
% case fabric:query_view(Db, Options, DDoc, ViewName,
% fun view_cb/2, VAcc, Args) of
% {ok, Resp} ->
% {ok, Resp#vacc.resp};
% {error, Error} ->
% throw(Error)
% end.
% {ok, Resp} = fabric:query_view(Db, Options, DDoc, ViewName,
% fun view_cb/2, VAcc, Args),
% {ok, Resp#vacc.resp}.
% % TODO: This might just be a debugging leftover, we might be able
% % to undo this by just returning {ok, Resp#vacc.resp}
% % However, this *might* be here because we need to handle
% % errors here now, because access might tell us to.
% case fabric:query_view(Db, Options, DDoc, ViewName,
% fun view_cb/2, VAcc, Args) of
% {ok, Resp} ->
% {ok, Resp#vacc.resp};
% {error, Error} ->
% throw(Error)
% end.

{ok, Resp} = fabric:query_view(
Db,
Expand Down
64 changes: 30 additions & 34 deletions src/couch/src/couch_access_native_proc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
-module(couch_access_native_proc).
-behavior(gen_server).


-export([
start_link/0,
set_timeout/2,
Expand All @@ -29,71 +28,55 @@
code_change/3
]).


-record(st, {
indexes = [],
timeout = 5000 % TODO: make configurable
% TODO: make configurable
timeout = 5000
}).

start_link() ->
gen_server:start_link(?MODULE, [], []).


set_timeout(Pid, TimeOut) when is_integer(TimeOut), TimeOut > 0 ->
gen_server:call(Pid, {set_timeout, TimeOut}).


prompt(Pid, Data) ->
gen_server:call(Pid, {prompt, Data}).


init(_) ->
{ok, #st{}}.


terminate(_Reason, _St) ->
ok.


handle_call({set_timeout, TimeOut}, _From, St) ->
{reply, ok, St#st{timeout=TimeOut}};

{reply, ok, St#st{timeout = TimeOut}};
handle_call({prompt, [<<"reset">>]}, _From, St) ->
{reply, true, St#st{indexes=[]}};

{reply, true, St#st{indexes = []}};
handle_call({prompt, [<<"reset">>, _QueryConfig]}, _From, St) ->
{reply, true, St#st{indexes=[]}};

{reply, true, St#st{indexes = []}};
handle_call({prompt, [<<"add_fun">>, IndexInfo]}, _From, St) ->
{reply, true, St};

handle_call({prompt, [<<"map_doc">>, Doc]}, _From, St) ->
{reply, map_doc(St, mango_json:to_binary(Doc)), St};

handle_call({prompt, [<<"reduce">>, _, _]}, _From, St) ->
{reply, null, St};

handle_call({prompt, [<<"rereduce">>, _, _]}, _From, St) ->
{reply, null, St};

handle_call({prompt, [<<"index_doc">>, Doc]}, _From, St) ->
{reply, [[]], St};

handle_call(Msg, _From, St) ->
{stop, {invalid_call, Msg}, {invalid_call, Msg}, St}.

handle_cast(garbage_collect, St) ->
erlang:garbage_collect(),
{noreply, St};

handle_cast(Msg, St) ->
{stop, {invalid_cast, Msg}, St}.


handle_info(Msg, St) ->
{stop, {invalid_info, Msg}, St}.


code_change(_OldVsn, St, _Extra) ->
{ok, St}.

Expand All @@ -115,29 +98,42 @@ code_change(_OldVsn, St, _Extra) ->
map_doc(_St, {Doc}) ->
case couch_util:get_value(<<"_access">>, Doc) of
undefined ->
[[],[]]; % do not index this doc
% do not index this doc
[[], []];
Access when is_list(Access) ->
Id = couch_util:get_value(<<"_id">>, Doc),
Rev = couch_util:get_value(<<"_rev">>, Doc),
Seq = couch_util:get_value(<<"_seq">>, Doc),
Deleted = couch_util:get_value(<<"_deleted">>, Doc, false),
BodySp = couch_util:get_value(<<"_body_sp">>, Doc),
% by-access-id
ById = case Deleted of
false ->
lists:map(fun(UserOrRole) -> [
[[UserOrRole, Id], Rev]
] end, Access);
_True -> [[]]
end,
ById =
case Deleted of
false ->
lists:map(
fun(UserOrRole) ->
[
[[UserOrRole, Id], Rev]
]
end,
Access
);
_True ->
[[]]
end,

% by-access-seq
BySeq = lists:map(fun(UserOrRole) -> [
[[UserOrRole, Seq], [{rev, Rev}, {deleted, Deleted}, {body_sp, BodySp}]]
] end, Access),
BySeq = lists:map(
fun(UserOrRole) ->
[
[[UserOrRole, Seq], [{rev, Rev}, {deleted, Deleted}, {body_sp, BodySp}]]
]
end,
Access
),
ById ++ BySeq;
Else ->
% TODO: no comprende: should not be needed once we implement
% _access field validation
[[],[]]
[[], []]
end.
1 change: 0 additions & 1 deletion src/couch/src/couch_bt_engine.erl
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,6 @@ id_tree_split(#full_doc_info{} = Info) ->
id_tree_join(Id, {HighSeq, Deleted, DiskTree}) ->
% Handle old formats before data_size was added
id_tree_join(Id, {HighSeq, Deleted, #size_info{}, DiskTree});

id_tree_join(Id, {HighSeq, Deleted, Sizes, DiskTree}) ->
id_tree_join(Id, {HighSeq, Deleted, Sizes, DiskTree, []});
id_tree_join(Id, {HighSeq, Deleted, Sizes, DiskTree, Access}) ->
Expand Down
8 changes: 5 additions & 3 deletions src/couch/src/couch_btree.erl
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,11 @@ full_reduce_with_options(Bt, Options0) ->
end,
[UserName] = proplists:get_value(start_key, Options0, <<"">>),
EndKey = {[UserName, {[]}]},
Options = Options0 ++ [
{end_key, EndKey}
],
Options =
Options0 ++
[
{end_key, EndKey}
],
fold_reduce(Bt, CountFun, 0, Options).

size(#btree{root = nil}) ->
Expand Down
Loading

0 comments on commit c4d4373

Please sign in to comment.