From d63e8cde806ed91dd386b292de01ddeca57e08f8 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Sat, 9 Sep 2023 18:47:29 -0700 Subject: [PATCH] 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. --- Library/Homebrew/dev-cmd/audit.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index ee11cb649e..2bfe5419a9 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -187,6 +187,8 @@ module Homebrew spdx_license_data = SPDX.license_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| path = f.path @@ -208,7 +210,7 @@ module Homebrew SimulateSystem.with os: os, arch: arch do 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) }