Merge pull request #3059 from MikeMcQuaid/why-search-take-so-long
search: explain why it takes the time it does.
This commit is contained in:
commit
8518ffdee1
@ -58,12 +58,14 @@ module Homebrew
|
||||
regex = query_regexp(query)
|
||||
local_results = search_formulae(regex)
|
||||
puts Formatter.columns(local_results) unless local_results.empty?
|
||||
|
||||
tap_results = search_taps(query)
|
||||
puts Formatter.columns(tap_results) unless tap_results.empty?
|
||||
|
||||
if $stdout.tty?
|
||||
count = local_results.length + tap_results.length
|
||||
|
||||
ohai "Searching blacklisted, migrated and deleted formulae..."
|
||||
if reason = Homebrew::MissingFormula.reason(query, silent: true)
|
||||
if count > 0
|
||||
puts
|
||||
@ -101,6 +103,11 @@ module Homebrew
|
||||
end
|
||||
|
||||
def search_taps(query)
|
||||
return [] if ENV["HOMEBREW_NO_GITHUB_API"]
|
||||
|
||||
# Use stderr to avoid breaking parsed output
|
||||
$stderr.puts Formatter.headline("Searching taps on GitHub...", color: :blue)
|
||||
|
||||
valid_dirnames = ["Formula", "HomebrewFormula", "Casks", "."].freeze
|
||||
matches = GitHub.search_code("user:Homebrew", "user:caskroom", "filename:#{query}", "extension:rb")
|
||||
[*matches].map do |match|
|
||||
@ -113,6 +120,9 @@ module Homebrew
|
||||
end
|
||||
|
||||
def search_formulae(regex)
|
||||
# Use stderr to avoid breaking parsed output
|
||||
$stderr.puts Formatter.headline("Searching local taps...", color: :blue)
|
||||
|
||||
aliases = Formula.alias_full_names
|
||||
results = (Formula.full_names + aliases).grep(regex).sort
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ describe "brew search", :integration_test do
|
||||
it "supports searching by name" do
|
||||
expect { brew "search", "testball" }
|
||||
.to output(/testball/).to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
.and output(/Searching/).to_stderr
|
||||
.and be_a_success
|
||||
end
|
||||
|
||||
@ -25,10 +25,10 @@ describe "brew search", :integration_test do
|
||||
.and be_a_success
|
||||
end
|
||||
|
||||
it "falls back to a tap search when no formula is found" do
|
||||
it "falls back to a GitHub tap search when no formula is found", :needs_network do
|
||||
expect { brew "search", "caskroom/cask/firefox" }
|
||||
.to output(/firefox/).to_stdout
|
||||
.and not_to_output.to_stderr
|
||||
.and output(/Searching/).to_stderr
|
||||
.and be_a_success
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user