Significantly improve fetch speed of bottles

This commit is contained in:
Bo Anderson 2023-06-22 14:25:18 +01:00
parent 8d9aa9070a
commit 6d8b033eff
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
3 changed files with 11 additions and 7 deletions

View File

@ -628,8 +628,10 @@ class CurlGitHubPackagesDownloadStrategy < CurlDownloadStrategy
private private
def resolved_basename def resolve_url_basename_time_file_size(url, timeout: nil)
@resolved_basename.presence || super return super if @resolved_basename.blank?
[url, @resolved_basename, nil, nil, false]
end end
end end

View File

@ -36,11 +36,11 @@ describe CurlDownloadStrategy do
it "calls curl with default arguments" do it "calls curl with default arguments" do
expect(strategy).to receive(:curl).with( expect(strategy).to receive(:curl).with(
"--remote-time",
"--output", an_instance_of(Pathname),
# example.com supports partial requests. # example.com supports partial requests.
"--continue-at", "-", "--continue-at", "-",
"--location", "--location",
"--remote-time",
"--output", an_instance_of(Pathname),
url, url,
an_instance_of(Hash) an_instance_of(Hash)
) )

View File

@ -173,9 +173,9 @@ module Utils
destination = Pathname(to) destination = Pathname(to)
destination.dirname.mkpath destination.dirname.mkpath
args = ["--location", "--remote-time", "--output", destination, *args] args = ["--location", *args]
if try_partial if try_partial && destination.exist?
headers = begin headers = begin
parsed_output = curl_headers(*args, **options, wanted_headers: ["accept-ranges"]) parsed_output = curl_headers(*args, **options, wanted_headers: ["accept-ranges"])
parsed_output.fetch(:responses).last&.fetch(:headers) || {} parsed_output.fetch(:responses).last&.fetch(:headers) || {}
@ -189,7 +189,7 @@ module Utils
supports_partial = headers.fetch("accept-ranges", "none") != "none" supports_partial = headers.fetch("accept-ranges", "none") != "none"
content_length = headers["content-length"]&.to_i content_length = headers["content-length"]&.to_i
if supports_partial && destination.exist? if supports_partial
# We've already downloaded all bytes. # We've already downloaded all bytes.
return if destination.size == content_length return if destination.size == content_length
@ -197,6 +197,8 @@ module Utils
end end
end end
args = ["--remote-time", "--output", destination, *args]
curl(*args, **options) curl(*args, **options)
end end