aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorXu Cheng2015-06-16 17:55:19 +0800
committerXu Cheng2015-06-18 14:46:29 +0800
commit6af47815b0a1168cfc787a38d8e48eb6c467f0a4 (patch)
treeee06fb3051d8532945b649c266fdffc040dc70ca /Library
parent7a59a3ee37966ad2378a3d96fbedde42506c5e00 (diff)
downloadbrew-6af47815b0a1168cfc787a38d8e48eb6c467f0a4.tar.bz2
search: cache remote tap formulae
Closes Homebrew/homebrew#40775. Signed-off-by: Xu Cheng <xucheng@me.com>
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/cmd/search.rb34
1 files changed, 17 insertions, 17 deletions
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb
index 942a14c7c..bcb66f362 100644
--- a/Library/Homebrew/cmd/search.rb
+++ b/Library/Homebrew/cmd/search.rb
@@ -108,36 +108,36 @@ module Homebrew
return []
end
- results = []
- tree = {}
+ @@remote_tap_formulae ||= Hash.new do |cache, key|
+ user, repo = key.split("/", 2)
+ tree = {}
- GitHub.open "https://api.github.com/repos/#{user}/homebrew-#{repo}/git/trees/HEAD?recursive=1" do |json|
- user = user.downcase if user == "Homebrew" # special handling for the Homebrew organization
- json["tree"].each do |object|
- next unless object["type"] == "blob"
+ GitHub.open "https://api.github.com/repos/#{user}/homebrew-#{repo}/git/trees/HEAD?recursive=1" do |json|
+ json["tree"].each do |object|
+ next unless object["type"] == "blob"
- subtree, file = File.split(object["path"])
+ subtree, file = File.split(object["path"])
- if File.extname(file) == ".rb"
- tree[subtree] ||= []
- tree[subtree] << file
+ if File.extname(file) == ".rb"
+ tree[subtree] ||= []
+ tree[subtree] << file
+ end
end
end
- end
- paths = tree["Formula"] || tree["HomebrewFormula"] || tree["Casks"] || tree["."] || []
- paths.each do |path|
- name = File.basename(path, ".rb")
- results << "#{user}/#{repo}/#{name}" if rx === name
+ paths = tree["Formula"] || tree["HomebrewFormula"] || tree["Casks"] || tree["."] || []
+ cache[key] = paths.map { |path| File.basename(path, ".rb") }
end
+
+ names = @@remote_tap_formulae["#{user}/#{repo}"]
+ user = user.downcase if user == "Homebrew" # special handling for the Homebrew organization
+ names.select { |name| rx === name }.map { |name| "#{user}/#{repo}/#{name}" }
rescue GitHub::HTTPNotFoundError => e
opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`"
[]
rescue GitHub::Error => e
SEARCH_ERROR_QUEUE << e
[]
- else
- results
end
def search_formulae rx