Enable download queue for single formula/cask API fetches

This commit is contained in:
Rylan Polster 2025-08-10 22:45:59 -04:00
parent d3aac3fa5f
commit 480eeb4246
No known key found for this signature in database
3 changed files with 35 additions and 7 deletions

View File

@ -16,9 +16,23 @@ module Homebrew
private_class_method :cache private_class_method :cache
sig { params(token: String).returns(T::Hash[String, T.untyped]) } sig { params(name: String).returns(T::Hash[String, T.untyped]) }
def self.fetch(token) def self.cask_json(name)
Homebrew::API.fetch "cask/#{token}.json" fetch_cask_json! name if !cache.key?("cask_json") || !cache.fetch("cask_json").key?(name)
cache.fetch("cask_json").fetch(name)
end
sig { params(name: String, download_queue: T.nilable(DownloadQueue)).void }
def self.fetch_cask_json!(name, download_queue: nil)
endpoint = "cask/#{name}.json"
json_cask, updated = Homebrew::API.fetch_json_api_file endpoint, download_queue: download_queue
return if download_queue
json_cask = JSON.parse((HOMEBREW_CACHE_API/endpoint).read) unless updated
cache["cask_json"] ||= {}
cache["cask_json"][name] = json_cask
end end
sig { params(cask: ::Cask::Cask, download_queue: T.nilable(Homebrew::DownloadQueue)).returns(Homebrew::API::SourceDownload) } sig { params(cask: ::Cask::Cask, download_queue: T.nilable(Homebrew::DownloadQueue)).returns(Homebrew::API::SourceDownload) }

View File

@ -17,8 +17,22 @@ module Homebrew
private_class_method :cache private_class_method :cache
sig { params(name: String).returns(T::Hash[String, T.untyped]) } sig { params(name: String).returns(T::Hash[String, T.untyped]) }
def self.fetch(name) def self.formula_json(name)
Homebrew::API.fetch "formula/#{name}.json" fetch_formula_json! name if !cache.key?("formula_json") || !cache.fetch("formula_json").key?(name)
cache.fetch("formula_json").fetch(name)
end
sig { params(name: String, download_queue: T.nilable(DownloadQueue)).void }
def self.fetch_formula_json!(name, download_queue: nil)
endpoint = "formula/#{name}.json"
json_formula, updated = Homebrew::API.fetch_json_api_file endpoint, download_queue: download_queue
return if download_queue
json_formula = JSON.parse((HOMEBREW_CACHE_API/endpoint).read) unless updated
cache["formula_json"] ||= {}
cache["formula_json"][name] = json_formula
end end
sig { params(formula: ::Formula, download_queue: T.nilable(Homebrew::DownloadQueue)).returns(Homebrew::API::SourceDownload) } sig { params(formula: ::Formula, download_queue: T.nilable(Homebrew::DownloadQueue)).returns(Homebrew::API::SourceDownload) }

View File

@ -329,7 +329,7 @@ module Utils
require "api" require "api"
json = Homebrew::API::Formula.fetch formula.name json = Homebrew::API::Formula.formula_json formula.name
return if json.blank? || json["analytics"].blank? return if json.blank? || json["analytics"].blank?
output_analytics(json, args:) output_analytics(json, args:)
@ -345,7 +345,7 @@ module Utils
require "api" require "api"
json = Homebrew::API::Cask.fetch cask.token json = Homebrew::API::Cask.cask_json cask.token
return if json.blank? || json["analytics"].blank? return if json.blank? || json["analytics"].blank?
output_analytics(json, args:) output_analytics(json, args:)