Update api code to load internal JSON v3 file
This commit is contained in:
parent
ece7e5d5b9
commit
d64de40e52
@ -184,6 +184,13 @@ module Homebrew
|
||||
|
||||
Tap.fetch(org, repo)
|
||||
end
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def self.internal_json_v3?
|
||||
return @internal_json_v3 if defined?(@internal_json_v3)
|
||||
|
||||
@internal_json_v3 = ENV["HOMEBREW_INTERNAL_JSON_V3"].present?
|
||||
end
|
||||
end
|
||||
|
||||
# @api private
|
||||
|
@ -39,6 +39,10 @@ module Homebrew
|
||||
|
||||
sig { returns(T::Boolean) }
|
||||
def self.download_and_cache_data!
|
||||
if Homebrew::API.internal_json_v3?
|
||||
json_formulae, updated = Homebrew::API.fetch_json_api_file "internal/v3/homebrew-core.jws.json"
|
||||
overwrite_cache! T.cast(json_formulae, T::Hash[String, T.untyped])
|
||||
else
|
||||
json_formulae, updated = Homebrew::API.fetch_json_api_file "formula.jws.json"
|
||||
|
||||
cache["aliases"] = {}
|
||||
@ -53,6 +57,7 @@ module Homebrew
|
||||
|
||||
[json_formula["name"], json_formula.except("name")]
|
||||
end
|
||||
end
|
||||
|
||||
updated
|
||||
end
|
||||
@ -88,6 +93,28 @@ module Homebrew
|
||||
cache["renames"]
|
||||
end
|
||||
|
||||
sig { returns(Hash) }
|
||||
def self.tap_migrations
|
||||
# Not sure that we need to reload here.
|
||||
unless cache.key?("tap_migrations")
|
||||
json_updated = download_and_cache_data!
|
||||
write_names_and_aliases(regenerate: json_updated)
|
||||
end
|
||||
|
||||
cache["tap_migrations"]
|
||||
end
|
||||
|
||||
sig { returns(String) }
|
||||
def self.tap_git_head
|
||||
# Note sure we need to reload here.
|
||||
unless cache.key?("tap_git_head")
|
||||
json_updated = download_and_cache_data!
|
||||
write_names_and_aliases(regenerate: json_updated)
|
||||
end
|
||||
|
||||
cache["tap_git_head"]
|
||||
end
|
||||
|
||||
sig { params(regenerate: T::Boolean).void }
|
||||
def self.write_names_and_aliases(regenerate: false)
|
||||
download_and_cache_data! unless cache.key?("formulae")
|
||||
|
@ -7,6 +7,11 @@ module Cachable
|
||||
@cache ||= T.let({}, T.nilable(T::Hash[T.untyped, T.untyped]))
|
||||
end
|
||||
|
||||
sig { params(hash: T.nilable(T::Hash[T.untyped, T.untyped])).void }
|
||||
def overwrite_cache!(hash)
|
||||
@cache = hash
|
||||
end
|
||||
|
||||
sig { void }
|
||||
def clear_cache
|
||||
cache.clear
|
||||
|
@ -1101,6 +1101,8 @@ class CoreTap < AbstractCoreTap
|
||||
@tap_migrations ||= if Homebrew::EnvConfig.no_install_from_api?
|
||||
ensure_installed!
|
||||
super
|
||||
elsif Homebrew::API.internal_json_v3?
|
||||
Homebrew::API::Formula.tap_migrations
|
||||
else
|
||||
migrations, = Homebrew::API.fetch_json_api_file "formula_tap_migrations.jws.json",
|
||||
stale_seconds: TAP_MIGRATIONS_STALE_SECONDS
|
||||
|
Loading…
x
Reference in New Issue
Block a user