From 8993ebca88e6462502d2bddae5393c54ba876a3d Mon Sep 17 00:00:00 2001 From: Steve Hahn <9423671+steveh7812@users.noreply.github.com> Date: Tue, 19 Jul 2022 17:41:27 -0700 Subject: [PATCH 1/2] use --time-cond when caching the formula api json --- Library/Homebrew/api/formula.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/api/formula.rb b/Library/Homebrew/api/formula.rb index a70fe31b8c..02427b072c 100644 --- a/Library/Homebrew/api/formula.rb +++ b/Library/Homebrew/api/formula.rb @@ -33,7 +33,7 @@ module Homebrew if cached_formula_json_file.exist? last_modified = cached_formula_json_file.mtime.utc last_modified = last_modified.strftime("%a, %d %b %Y %H:%M:%S GMT") - curl_args = ["--header", "If-Modified-Since: #{last_modified}", *curl_args] + curl_args = ["--time-cond", last_modified, *curl_args] unless cached_formula_json_file.empty? end curl_download(*curl_args, to: HOMEBREW_CACHE_API/"#{formula_api_path}.json", max_time: 5) From 9f27bd4c678eb6f110744860a12fa42fae338e3b Mon Sep 17 00:00:00 2001 From: Steve Hahn <9423671+steveh7812@users.noreply.github.com> Date: Wed, 20 Jul 2022 11:19:24 -0700 Subject: [PATCH 2/2] simplify cached_formula_json_file check --- Library/Homebrew/api/formula.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/api/formula.rb b/Library/Homebrew/api/formula.rb index 02427b072c..cd65bdbe32 100644 --- a/Library/Homebrew/api/formula.rb +++ b/Library/Homebrew/api/formula.rb @@ -30,10 +30,8 @@ module Homebrew def all_formulae @all_formulae ||= begin curl_args = %w[--compressed --silent https://formulae.brew.sh/api/formula.json] - if cached_formula_json_file.exist? - last_modified = cached_formula_json_file.mtime.utc - last_modified = last_modified.strftime("%a, %d %b %Y %H:%M:%S GMT") - curl_args = ["--time-cond", last_modified, *curl_args] unless cached_formula_json_file.empty? + if cached_formula_json_file.exist? && !cached_formula_json_file.empty? + curl_args.prepend("--time-cond", cached_formula_json_file) end curl_download(*curl_args, to: HOMEBREW_CACHE_API/"#{formula_api_path}.json", max_time: 5)