Use bulk delete in CellarService when possible

This commit is contained in:
Frederic Merizen 2018-02-20 15:16:34 +01:00
parent 27d76ea226
commit 6907650bcb
2 changed files with 13 additions and 12 deletions

View file

@ -61,7 +61,9 @@ module ActiveStorage
# TODO: error handling # TODO: error handling
instrument :delete, key: key do instrument :delete, key: key do
http_start do |http| http_start do |http|
perform_delete(http, key) request = Net::HTTP::Delete.new(URI::join(@endpoint, "/#{key}"))
sign(request, key)
http.request(request)
end end
end end
end end
@ -71,10 +73,16 @@ module ActiveStorage
# TODO: handle pagination if more than 1000 keys # TODO: handle pagination if more than 1000 keys
instrument :delete_prefixed, prefix: prefix do instrument :delete_prefixed, prefix: prefix do
http_start do |http| http_start do |http|
list_prefixed(http, prefix).each do |key| keys = list_prefixed(http, prefix)
# TODO: use bulk delete instead request_body = bulk_deletion_request_body(keys)
perform_delete(http, key) checksum = Digest::MD5.base64digest(request_body)
end request = Net::HTTP::Post.new(URI::join(@endpoint, "/?delete"))
request.content_type = 'text/xml'
request['Content-MD5'] = checksum
request['Content-Length'] = request_body.length
request.body = request_body
sign(request, "?delete", checksum: checksum)
http.request(request)
end end
end end
end end
@ -198,12 +206,6 @@ module ActiveStorage
builder.to_xml builder.to_xml
end end
def perform_delete(http, key)
request = Net::HTTP::Delete.new(URI::join(@endpoint, "/#{key}"))
sign(request, key)
http.request(request)
end
def with_io_length(io) def with_io_length(io)
if io.respond_to?(:size) && io.respond_to?(:pos) if io.respond_to?(:size) && io.respond_to?(:pos)
yield(io, io.size - io.pos) yield(io, io.size - io.pos)

View file

@ -148,7 +148,6 @@ describe 'CellarService' do
let(:expected_response) do let(:expected_response) do
'<?xml version="1.0" encoding="UTF-8"?> '<?xml version="1.0" encoding="UTF-8"?>
<Delete> <Delete>
<Quiet>true</Quiet>
<Object> <Object>
<Key>chapi</Key> <Key>chapi</Key>
</Object> </Object>