mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
tap: fix performance regression in *_files_by_name
We essentially stopped caching these accidentally and they get called every time we try to load a cask or formula from the API. It gets really, really, really slow. I ran `brew deps --casks --eval-all` before and after the changes. I let it run for 3 minutes before killing it. No output had been printed to the screen. It finished printing all output (pages and pages of it) in less than a minute. --- This should match the caching behavior we had before the recent changes in these two PRs. - https://github.com/Homebrew/brew/pull/16777 - https://github.com/Homebrew/brew/pull/16775
This commit is contained in:
parent
0a3549b7f2
commit
99d5200db3
@ -1211,14 +1211,16 @@ class CoreTap < AbstractCoreTap
|
|||||||
def formula_files_by_name
|
def formula_files_by_name
|
||||||
return super if Homebrew::EnvConfig.no_install_from_api?
|
return super if Homebrew::EnvConfig.no_install_from_api?
|
||||||
|
|
||||||
tap_path = path.to_s
|
@formula_files_by_name ||= begin
|
||||||
Homebrew::API::Formula.all_formulae.each_with_object({}) do |item, hash|
|
tap_path = path.to_s
|
||||||
name, formula_hash = item
|
Homebrew::API::Formula.all_formulae.each_with_object({}) do |item, hash|
|
||||||
# If there's more than one item with the same path: use the longer one to prioritise more specific results.
|
name, formula_hash = item
|
||||||
existing_path = hash[name]
|
# If there's more than one item with the same path: use the longer one to prioritise more specific results.
|
||||||
# Pathname equivalent is slow in a tight loop
|
existing_path = hash[name]
|
||||||
new_path = File.join(tap_path, formula_hash.fetch("ruby_source_path"))
|
# Pathname equivalent is slow in a tight loop
|
||||||
hash[name] = Pathname(new_path) if existing_path.nil? || existing_path.to_s.length < new_path.length
|
new_path = File.join(tap_path, formula_hash.fetch("ruby_source_path"))
|
||||||
|
hash[name] = Pathname(new_path) if existing_path.nil? || existing_path.to_s.length < new_path.length
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1279,7 +1281,7 @@ class CoreCaskTap < AbstractCoreTap
|
|||||||
def cask_files_by_name
|
def cask_files_by_name
|
||||||
return super if Homebrew::EnvConfig.no_install_from_api?
|
return super if Homebrew::EnvConfig.no_install_from_api?
|
||||||
|
|
||||||
Homebrew::API::Cask.all_casks.each_with_object({}) do |item, hash|
|
@cask_files_by_name ||= Homebrew::API::Cask.all_casks.each_with_object({}) do |item, hash|
|
||||||
name, cask_hash = item
|
name, cask_hash = item
|
||||||
# If there's more than one item with the same path: use the longer one to prioritise more specific results.
|
# If there's more than one item with the same path: use the longer one to prioritise more specific results.
|
||||||
existing_path = hash[name]
|
existing_path = hash[name]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user