Speed up cask search

Add new method to get all cask names
without using Cask.all which is slow
in this case.
This commit is contained in:
apainintheneck 2022-12-13 23:38:44 -08:00
parent ed3789a0bb
commit 363df2a648
2 changed files with 11 additions and 1 deletions

View File

@ -38,6 +38,16 @@ module Cask
end.compact
end
def self.full_names
Tap.flat_map do |tap|
next tap.cask_tokens.blank?
next tap.cask_tokens if tap.user == "Homebrew"
name = tap.name
tap.cask_tokens.map { |tok| "#{name}/#{tok}" }
end.flatten
end
def tap
return super if block_given? # Object#tap

View File

@ -37,7 +37,7 @@ module Homebrew
results = cask_tokens.extend(Searchable)
.search(string_or_regex)
cask_names = Cask::Cask.all.map(&:full_name)
cask_names = Cask::Cask.full_names
results += DidYouMean::SpellChecker.new(dictionary: cask_names)
.correct(string_or_regex)