Skip to content

Commit

Permalink
wm_timeseries: simplify batch put data extraction from json
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrei Zavada committed Mar 2, 2016
1 parent c6c0b5e commit 4e20c20
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions src/riak_kv_wm_timeseries.erl
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ validate_request(RD, Ctx) ->
-spec validate_request_v1(#wm_reqdata{}, #ctx{}) ->
?CB_RV_SPEC.
validate_request_v1(RD, Ctx = #ctx{method = 'POST'}) ->
Json = extract_json(RD),
Json = binary_to_list(wrq:req_body(RD)),
case extract_data(Json) of
Data when Data /= undefined ->
valid_params(
Expand Down Expand Up @@ -228,18 +228,8 @@ validate_request_v1(RD, Ctx = #ctx{method = 'DELETE', table = Table,
handle_error(Reason, RD, Ctx)
end.

extract_json(RD) ->
case proplists:get_value("json", RD#wm_reqdata.req_qs) of
undefined ->
%% if it was a PUT or POST, data is in body
binary_to_list(wrq:req_body(RD));
BodyInPost ->
BodyInPost
end.

%% because, techically, key and data are 'arguments', we check they
%% are well-formed, too.
-spec extract_data(binary()) -> term().
-spec extract_data([byte()]) -> undefined|any().
extract_data(Json) ->
try mochijson2:decode(Json) of
Decoded when is_list(Decoded) ->
Expand Down Expand Up @@ -354,11 +344,11 @@ convert_field(T, F, timestamp, V) ->
{F, GoodValue}
end.


ensure_lk_order_and_strip(LK, FVList) ->
[proplists:get_value(F, FVList)
|| #param_v1{name = F} <- LK].


-spec valid_params(#wm_reqdata{}, #ctx{}) -> ?CB_RV_SPEC.
valid_params(RD, Ctx) ->
case wrq:get_qs_value("timeout", none, RD) of
Expand All @@ -374,6 +364,7 @@ valid_params(RD, Ctx) ->
end
end.


-spec check_permissions(#wm_reqdata{}, #ctx{}) -> {term(), #wm_reqdata{}, #ctx{}}.
check_permissions(RD, Ctx = #ctx{security = undefined}) ->
{true, RD, Ctx};
Expand Down

0 comments on commit 4e20c20

Please sign in to comment.