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)
|
Tap.fetch(org, repo)
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
# @api private
|
# @api private
|
||||||
|
@ -39,19 +39,24 @@ module Homebrew
|
|||||||
|
|
||||||
sig { returns(T::Boolean) }
|
sig { returns(T::Boolean) }
|
||||||
def self.download_and_cache_data!
|
def self.download_and_cache_data!
|
||||||
json_formulae, updated = Homebrew::API.fetch_json_api_file "formula.jws.json"
|
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"] = {}
|
cache["aliases"] = {}
|
||||||
cache["renames"] = {}
|
cache["renames"] = {}
|
||||||
cache["formulae"] = json_formulae.to_h do |json_formula|
|
cache["formulae"] = json_formulae.to_h do |json_formula|
|
||||||
json_formula["aliases"].each do |alias_name|
|
json_formula["aliases"].each do |alias_name|
|
||||||
cache["aliases"][alias_name] = json_formula["name"]
|
cache["aliases"][alias_name] = json_formula["name"]
|
||||||
end
|
end
|
||||||
(json_formula["oldnames"] || [json_formula["oldname"]].compact).each do |oldname|
|
(json_formula["oldnames"] || [json_formula["oldname"]].compact).each do |oldname|
|
||||||
cache["renames"][oldname] = json_formula["name"]
|
cache["renames"][oldname] = json_formula["name"]
|
||||||
end
|
end
|
||||||
|
|
||||||
[json_formula["name"], json_formula.except("name")]
|
[json_formula["name"], json_formula.except("name")]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
updated
|
updated
|
||||||
@ -88,6 +93,28 @@ module Homebrew
|
|||||||
cache["renames"]
|
cache["renames"]
|
||||||
end
|
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 }
|
sig { params(regenerate: T::Boolean).void }
|
||||||
def self.write_names_and_aliases(regenerate: false)
|
def self.write_names_and_aliases(regenerate: false)
|
||||||
download_and_cache_data! unless cache.key?("formulae")
|
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]))
|
@cache ||= T.let({}, T.nilable(T::Hash[T.untyped, T.untyped]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sig { params(hash: T.nilable(T::Hash[T.untyped, T.untyped])).void }
|
||||||
|
def overwrite_cache!(hash)
|
||||||
|
@cache = hash
|
||||||
|
end
|
||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
def clear_cache
|
def clear_cache
|
||||||
cache.clear
|
cache.clear
|
||||||
|
@ -1101,6 +1101,8 @@ class CoreTap < AbstractCoreTap
|
|||||||
@tap_migrations ||= if Homebrew::EnvConfig.no_install_from_api?
|
@tap_migrations ||= if Homebrew::EnvConfig.no_install_from_api?
|
||||||
ensure_installed!
|
ensure_installed!
|
||||||
super
|
super
|
||||||
|
elsif Homebrew::API.internal_json_v3?
|
||||||
|
Homebrew::API::Formula.tap_migrations
|
||||||
else
|
else
|
||||||
migrations, = Homebrew::API.fetch_json_api_file "formula_tap_migrations.jws.json",
|
migrations, = Homebrew::API.fetch_json_api_file "formula_tap_migrations.jws.json",
|
||||||
stale_seconds: TAP_MIGRATIONS_STALE_SECONDS
|
stale_seconds: TAP_MIGRATIONS_STALE_SECONDS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user