Resource, CurlDownloadStrategy: Deduplicate the curl HEAD requests

Fixes #5357

* Eliminates getting a new strategy instance via Resource methods
* only call resolve_url_basename_time once and store the time result as
an instance variable for reuse
This commit is contained in:
Kevin Abel 2018-11-28 20:59:16 -06:00
parent 4cb61054df
commit 8fddd87472
No known key found for this signature in database
GPG Key ID: E0F7636DDDB96BF6
2 changed files with 7 additions and 5 deletions

View File

@ -329,12 +329,14 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
private
def resolved_url_and_basename
return @resolved_url_and_basename if defined?(@resolved_url_and_basename)
resolved_url, basename, = resolve_url_basename_time(url)
@resolved_url_and_basename = [resolved_url, basename]
[resolved_url, basename]
end
def resolve_url_basename_time(url)
@resolved_info_cache ||= {}
return @resolved_info_cache[url] if @resolved_info_cache.include?(url)
if ENV["HOMEBREW_ARTIFACT_DOMAIN"]
url = url.sub(%r{^((ht|f)tps?://)?}, ENV["HOMEBREW_ARTIFACT_DOMAIN"].chomp("/") + "/")
end
@ -373,7 +375,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
basename = filenames.last || parse_basename(redirect_url)
[redirect_url, basename, time]
@resolved_info_cache[url] = [redirect_url, basename, time]
end
def _fetch(url:, resolved_url:)

View File

@ -35,8 +35,8 @@ class Resource
end
def downloader
download_strategy.new(url, download_name, version,
mirrors: mirrors.dup, **specs)
@downloader ||= download_strategy.new(url, download_name, version,
mirrors: mirrors.dup, **specs)
end
# Removes /s from resource names; this allows go package names