cmd/audit: only flush formulary cache when needed

The cache here needs to be cleared when we are auditing multiple
os/arch combinations but not when we are running the audit only
for the current os/arch combination. This gives a 2x speed boost
to `brew audit --skip-style --except-version --tap=homebrew/core` locally.

In theory we could clear the cache less often by running all audits for
one os/arch combination at a time when auditing multiple os/arch combinations.
This would make the output a bit harder to follow and we don't seem to
run those checks on CI so I'm skipping that for now.
This commit is contained in:
apainintheneck 2023-09-09 18:47:29 -07:00
parent 502434cf44
commit d63e8cde80

View File

@ -187,6 +187,8 @@ module Homebrew
spdx_license_data = SPDX.license_data spdx_license_data = SPDX.license_data
spdx_exception_data = SPDX.exception_data spdx_exception_data = SPDX.exception_data
clear_formulary_cache = [args.os, args.arch].any?
formula_problems = audit_formulae.sort.each_with_object({}) do |f, problems| formula_problems = audit_formulae.sort.each_with_object({}) do |f, problems|
path = f.path path = f.path
@ -208,7 +210,7 @@ module Homebrew
SimulateSystem.with os: os, arch: arch do SimulateSystem.with os: os, arch: arch do
odebug "Auditing Formula #{f} on os #{os} and arch #{arch}" odebug "Auditing Formula #{f} on os #{os} and arch #{arch}"
Formulary.clear_cache Formulary.clear_cache if clear_formulary_cache
audit_proc = proc { FormulaAuditor.new(Formulary.factory(path), **options).tap(&:audit) } audit_proc = proc { FormulaAuditor.new(Formulary.factory(path), **options).tap(&:audit) }