rnewson commented on a change in pull request #1577: add
/_partition/partition/designdoc/ endpoints
URL: https://github.com/apache/couchdb/pull/1577#discussion_r212336580
##########
File path: src/chttpd/src/chttpd_db.erl
##########
@@ -250,24 +251,73 @@ handle_view_cleanup_req(Req, Db) ->
ok = fabric:cleanup_index_files_all_nodes(Db),
send_json(Req, 202, {[{ok, true}]}).
+
+handle_partition_design_req(#httpd{
+ path_parts=[DbName, <<"_partition">>, Partition, _Design, Name,
<<"_",_/binary>> = Action | _Rest]
+ }=Req, Db) ->
+
+ couch_doc:validate_docid(Partition, DbName),
+ validate_no_partition_in_qs(Req),
+
+ case mem3:is_partitioned(DbName) of
+ false -> throw({bad_request, <<"Database is not partitioned">>});
+ true -> ok
+ end,
+
+ DDoc = get_design_doc(DbName, Name),
+ Partitioned = couch_mrview:get_partitioned_opt(DDoc#doc.body, true),
+
+ case Partitioned of
+ true ->
+ Handler = chttpd_handlers:partition_design_handler(Action, fun
bad_action_partition_req/4),
+ Handler(Req, Db, DDoc, Partition);
+ false ->
+ throw({bad_request, <<"partition query is not supported in this
design doc.">>})
+ end;
+
+handle_partition_design_req(_Req, _Db) ->
+ throw({bad_request, <<"missing partition key">>}).
+
+
+bad_action_partition_req(Req, _Db, _DDoc, _PartitionKey) ->
+ chttpd:send_error(Req, 404, <<"partition_error">>, <<"Invalid path.">>).
+
+
handle_design_req(#httpd{
path_parts=[_DbName, _Design, Name, <<"_",_/binary>> = Action | _Rest]
}=Req, Db) ->
+ validate_no_partition_in_qs(Req),
DbName = mem3:dbname(couch_db:name(Db)),
- case ddoc_cache:open(DbName, <<"_design/", Name/binary>>) of
- {ok, DDoc} ->
- Handler = chttpd_handlers:design_handler(Action, fun bad_action_req/3),
- Handler(Req, Db, DDoc);
- Error ->
- throw(Error)
- end;
+ DDoc = get_design_doc(DbName, Name),
+ Handler = chttpd_handlers:design_handler(Action, fun bad_action_req/3),
+ Handler(Req, Db, DDoc);
handle_design_req(Req, Db) ->
db_req(Req, Db).
+
+get_design_doc(DbName, Name) ->
+ case ddoc_cache:open(DbName, <<"_design/", Name/binary>>) of
+ {ok, DDoc} ->
+ DDoc;
+ Error ->
+ throw(Error)
+ end.
+
+
+validate_no_partition_in_qs(Req) ->
+ case chttpd:qs_value(Req, "partition") of
+ undefined ->
+ ok;
+ _ ->
+ throw({bad_request, <<"Partition is not allowed in the query
string">>})
+ end.
+
+
bad_action_req(#httpd{path_parts=[_, _, Name|FileNameParts]}=Req, Db, _DDoc) ->
db_attachment_req(Req, Db, <<"_design/",Name/binary>>, FileNameParts).
+
Review comment:
ws only change.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services