iilyak commented on a change in pull request #3568:
URL: https://github.com/apache/couchdb/pull/3568#discussion_r633796802
##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -322,174 +360,201 @@ delete_db_req(#httpd{user_ctx=Ctx}=Req, DbName) ->
throw(Error)
end.
-do_db_req(#httpd{path_parts=[DbName|_], user_ctx=Ctx}=Req, Fun) ->
+do_db_req(#httpd{path_parts = [DbName | _], user_ctx = Ctx} = Req, Fun) ->
Options = [{user_ctx, Ctx}, {interactive, true}],
{ok, Db} = fabric2_db:open(DbName, Options),
Fun(Req, Db).
-db_req(#httpd{method='GET',path_parts=[_DbName]}=Req, Db) ->
+db_req(#httpd{method = 'GET', path_parts = [_DbName]} = Req, Db) ->
% measure the time required to generate the etag, see if it's worth it
T0 = os:timestamp(),
{ok, DbInfo} = fabric2_db:get_db_info(Db),
DeltaT = timer:now_diff(os:timestamp(), T0) / 1000,
couch_stats:update_histogram([couchdb, dbinfo], DeltaT),
send_json(Req, {DbInfo});
-
-db_req(#httpd{method='POST', path_parts=[DbName]}=Req, Db) ->
+db_req(#httpd{method = 'POST', path_parts = [DbName]} = Req, Db) ->
chttpd:validate_ctype(Req, "application/json"),
Doc0 = chttpd:json_body(Req),
Doc1 = couch_doc:from_json_obj_validate(Doc0, fabric2_db:name(Db)),
validate_attachment_names(Doc1),
- Doc2 = case Doc1#doc.id of
- <<"">> ->
- Doc1#doc{id=couch_uuids:new(), revs={0, []}};
- _ ->
- Doc1
- end,
+ Doc2 =
+ case Doc1#doc.id of
+ <<"">> ->
+ Doc1#doc{id = couch_uuids:new(), revs = {0, []}};
+ _ ->
+ Doc1
+ end,
Doc3 = read_att_data(Doc2),
DocId = Doc3#doc.id,
case chttpd:qs_value(Req, "batch") of
- "ok" ->
- % async_batching
- spawn(fun() ->
- case catch(fabric2_db:update_doc(Db, Doc3, [])) of
- {ok, _} ->
- chttpd_stats:incr_writes(),
- ok;
- {accepted, _} ->
- chttpd_stats:incr_writes(),
- ok;
- Error ->
- ?LOG_DEBUG(#{
- what => async_update_error,
- db => DbName,
- docid => DocId,
- details => Error
- }),
- couch_log:debug("Batch doc error (~s): ~p",[DocId, Error])
+ "ok" ->
+ % async_batching
+ spawn(fun() ->
+ case catch (fabric2_db:update_doc(Db, Doc3, [])) of
+ {ok, _} ->
+ chttpd_stats:incr_writes(),
+ ok;
+ {accepted, _} ->
+ chttpd_stats:incr_writes(),
+ ok;
+ Error ->
+ ?LOG_DEBUG(#{
+ what => async_update_error,
+ db => DbName,
+ docid => DocId,
+ details => Error
+ }),
+ couch_log:debug("Batch doc error (~s): ~p", [DocId,
Error])
end
end),
- send_json(Req, 202, [], {[
- {ok, true},
- {id, DocId}
- ]});
- _Normal ->
- % normal
- DocUrl = absolute_uri(Req, [$/, couch_util:url_encode(DbName),
- $/, couch_util:url_encode(DocId)]),
- case fabric2_db:update_doc(Db, Doc3, []) of
- {ok, NewRev} ->
- chttpd_stats:incr_writes(),
- HttpCode = 201;
- {accepted, NewRev} ->
- chttpd_stats:incr_writes(),
- HttpCode = 202
- end,
- send_json(Req, HttpCode, [{"Location", DocUrl}], {[
- {ok, true},
- {id, DocId},
- {rev, couch_doc:rev_to_str(NewRev)}
- ]})
+ send_json(
+ Req,
+ 202,
+ [],
+ {[
+ {ok, true},
+ {id, DocId}
+ ]}
+ );
+ _Normal ->
+ % normal
+ DocUrl = absolute_uri(Req, [
+ $/,
Review comment:
+1. I am glad erlfmt do not change literal characters.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]