Merge pull request #20524 from Homebrew/fetch_api_files_refactoring

Refactor Homebrew::API.fetch_api_files! to not take arguments.
This commit is contained in:
Mike McQuaid 2025-08-20 15:26:44 +00:00 committed by GitHub
commit e4e6185272
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 17 additions and 29 deletions

View File

@ -152,8 +152,14 @@ module Homebrew
json.except("variations")
end
sig { params(download_queue: T.nilable(DownloadQueue), stale_seconds: Integer).void }
def self.fetch_api_files!(download_queue: nil, stale_seconds: Homebrew::EnvConfig.api_auto_update_secs.to_i)
sig { void }
def self.fetch_api_files!
download_queue = if Homebrew::EnvConfig.download_concurrency > 1
require "download_queue"
Homebrew::DownloadQueue.new
end
stale_seconds = 86400 # 1 day
if Homebrew::EnvConfig.use_internal_api?
Homebrew::API::Internal.fetch_formula_api!(download_queue:, stale_seconds:)
Homebrew::API::Internal.fetch_cask_api!(download_queue:, stale_seconds:)
@ -163,6 +169,13 @@ module Homebrew
Homebrew::API::Cask.fetch_api!(download_queue:, stale_seconds:)
Homebrew::API::Cask.fetch_tap_migrations!(download_queue:, stale_seconds:)
end
return unless download_queue
begin
download_queue.fetch
ensure
download_queue.shutdown
end
end
sig { void }

View File

@ -89,18 +89,8 @@ begin
Homebrew.running_command = cmd
if cmd_class
if !Homebrew::EnvConfig.no_install_from_api? && Homebrew::EnvConfig.download_concurrency > 1
require "download_queue"
require "api"
require "api/formula"
require "api/cask"
download_queue = Homebrew::DownloadQueue.new
stale_seconds = 86400 # 1 day
Homebrew::API.fetch_api_files!(download_queue:, stale_seconds:)
begin
download_queue.fetch
ensure
download_queue.shutdown
end
Homebrew::API.fetch_api_files!
end
command_instance = cmd_class.new

View File

@ -231,23 +231,8 @@ module Homebrew
end
# Fetch JSON API files if needed.
download_queue = if Homebrew::EnvConfig.download_concurrency > 1
require "download_queue"
Homebrew::DownloadQueue.new
end
require "api"
require "api/formula"
require "api/cask"
stale_seconds = 86400 # 1 day
Homebrew::API.fetch_api_files!(download_queue:, stale_seconds:)
begin
download_queue&.fetch
ensure
download_queue&.shutdown
end
Homebrew::API.fetch_api_files!
# Codespaces HOMEBREW_PREFIX and /tmp are mounted 755 which makes Ruby warn constantly.
if (ENV["HOMEBREW_CODESPACES"] == "true") && (HOMEBREW_TEMP.to_s == "/tmp")