Use bulk delete in CellarService when possible
This commit is contained in:
parent
27d76ea226
commit
6907650bcb
2 changed files with 13 additions and 12 deletions
|
@ -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)
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue