Refactor Homebrew::API.fetch_api_files! to not take arguments.
Was thinking about this a bit and feels a bit nicer to DRY this up.
This commit is contained in:
parent
033138638f
commit
d2de1d5b7d
@ -152,8 +152,14 @@ module Homebrew
|
|||||||
json.except("variations")
|
json.except("variations")
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { params(download_queue: T.nilable(DownloadQueue), stale_seconds: Integer).void }
|
sig { void }
|
||||||
def self.fetch_api_files!(download_queue: nil, stale_seconds: Homebrew::EnvConfig.api_auto_update_secs.to_i)
|
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?
|
if Homebrew::EnvConfig.use_internal_api?
|
||||||
Homebrew::API::Internal.fetch_formula_api!(download_queue:, stale_seconds:)
|
Homebrew::API::Internal.fetch_formula_api!(download_queue:, stale_seconds:)
|
||||||
Homebrew::API::Internal.fetch_cask_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_api!(download_queue:, stale_seconds:)
|
||||||
Homebrew::API::Cask.fetch_tap_migrations!(download_queue:, stale_seconds:)
|
Homebrew::API::Cask.fetch_tap_migrations!(download_queue:, stale_seconds:)
|
||||||
end
|
end
|
||||||
|
return unless download_queue
|
||||||
|
|
||||||
|
begin
|
||||||
|
download_queue.fetch
|
||||||
|
ensure
|
||||||
|
download_queue.shutdown
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { void }
|
sig { void }
|
||||||
|
|||||||
@ -89,18 +89,8 @@ begin
|
|||||||
Homebrew.running_command = cmd
|
Homebrew.running_command = cmd
|
||||||
if cmd_class
|
if cmd_class
|
||||||
if !Homebrew::EnvConfig.no_install_from_api? && Homebrew::EnvConfig.download_concurrency > 1
|
if !Homebrew::EnvConfig.no_install_from_api? && Homebrew::EnvConfig.download_concurrency > 1
|
||||||
require "download_queue"
|
|
||||||
require "api"
|
require "api"
|
||||||
require "api/formula"
|
Homebrew::API.fetch_api_files!
|
||||||
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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
command_instance = cmd_class.new
|
command_instance = cmd_class.new
|
||||||
|
|||||||
@ -231,23 +231,8 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Fetch JSON API files if needed.
|
# 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"
|
||||||
require "api/formula"
|
Homebrew::API.fetch_api_files!
|
||||||
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
|
|
||||||
|
|
||||||
# Codespaces HOMEBREW_PREFIX and /tmp are mounted 755 which makes Ruby warn constantly.
|
# Codespaces HOMEBREW_PREFIX and /tmp are mounted 755 which makes Ruby warn constantly.
|
||||||
if (ENV["HOMEBREW_CODESPACES"] == "true") && (HOMEBREW_TEMP.to_s == "/tmp")
|
if (ENV["HOMEBREW_CODESPACES"] == "true") && (HOMEBREW_TEMP.to_s == "/tmp")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user