Skip to content

Commit f79d951

Browse files
committed
Add _purged_infos endpoint
- Expose the internal purged_infos API to users - Add tests and documentation for `_purged_infos`
1 parent 60cc6eb commit f79d951

File tree

6 files changed

+454
-443
lines changed

6 files changed

+454
-443
lines changed

src/chttpd/src/chttpd_db.erl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,15 @@ db_req(#httpd{method = 'POST', path_parts = [_, <<"_purge">>]} = Req, Db) ->
726726
send_json(Req, Code, {[{<<"purge_seq">>, null}, {<<"purged">>, {Json}}]});
727727
db_req(#httpd{path_parts = [_, <<"_purge">>]} = Req, _Db) ->
728728
send_method_not_allowed(Req, "POST");
729+
db_req(#httpd{method = 'GET', path_parts = [_, <<"_purged_infos">>]} = Req, Db) ->
730+
{ok, PurgedInfosRaw} = fabric:get_purged_infos(Db),
731+
PurgedInfos = [
732+
{[{id, Id}, {revs, [couch_doc:rev_to_str(Rev) || Rev <- Revs]}]}
733+
|| {Id, Revs} <- PurgedInfosRaw
734+
],
735+
send_json(Req, {[{purged_infos, PurgedInfos}]});
736+
db_req(#httpd{path_parts = [_, <<"_purged_infos">>]} = Req, _Db) ->
737+
send_method_not_allowed(Req, "GET");
729738
db_req(#httpd{method = 'GET', path_parts = [_, OP]} = Req, Db) when ?IS_ALL_DOCS(OP) ->
730739
case chttpd:qs_json_value(Req, "keys", nil) of
731740
Keys when is_list(Keys) ->
@@ -855,10 +864,12 @@ db_req(#httpd{method = 'PUT', path_parts = [_, <<"_purged_infos_limit">>]} = Req
855864
throw(Error)
856865
end;
857866
_ ->
858-
throw({bad_request, "`purge_infos_limit` must be positive integer"})
867+
throw({bad_request, "`purged_infos_limit` must be positive integer"})
859868
end;
860869
db_req(#httpd{method = 'GET', path_parts = [_, <<"_purged_infos_limit">>]} = Req, Db) ->
861870
send_json(Req, fabric:get_purge_infos_limit(Db));
871+
db_req(#httpd{path_parts = [_, <<"_purged_infos_limit">>]} = Req, _Db) ->
872+
send_method_not_allowed(Req, "GET,PUT");
862873
% Special case to enable using an unencoded slash in the URL of design docs,
863874
% as slashes in document IDs must otherwise be URL encoded.
864875
db_req(

0 commit comments

Comments
 (0)