Commit 2c8ce4f6 authored by Fabio Pelosin's avatar Fabio Pelosin

[SourcesManager] Improve search performance

parent 3fe56ec1
...@@ -59,6 +59,7 @@ module Pod ...@@ -59,6 +59,7 @@ module Pod
# @return [Array<Set>] The sets that contain the search term. # @return [Array<Set>] The sets that contain the search term.
# #
def search_by_name(query, full_text_search = false) def search_by_name(query, full_text_search = false)
if full_text_search
set_names = [] set_names = []
updated_search_index.each do |name, set_data| updated_search_index.each do |name, set_data|
text = name.dup text = name.dup
...@@ -69,8 +70,10 @@ module Pod ...@@ -69,8 +70,10 @@ module Pod
end end
set_names << name if text.downcase.include?(query.downcase) set_names << name if text.downcase.include?(query.downcase)
end end
sets = set_names.sort.map { |name| aggregate.represenative_set(name) } sets = set_names.sort.map { |name| aggregate.represenative_set(name) }
else
sets = aggregate.search_by_name(query, false)
end
if sets.empty? if sets.empty?
extra = ", author, summary, or description" if full_text_search extra = ", author, summary, or description" if full_text_search
raise Informative, "Unable to find a pod with name#{extra} matching `#{query}`" raise Informative, "Unable to find a pod with name#{extra} matching `#{query}`"
...@@ -86,9 +89,13 @@ module Pod ...@@ -86,9 +89,13 @@ module Pod
# - description # - description
# - authors # - authors
# #
# @note This operation is fairly expensive, because of the YAML
# conversion.
#
# @return [Hash{String => String}] The up to date search data. # @return [Hash{String => String}] The up to date search data.
# #
def updated_search_index def updated_search_index
unless @updated_search_index
if search_index_path.exist? if search_index_path.exist?
stored_index = YAML.load(search_index_path.read) stored_index = YAML.load(search_index_path.read)
if stored_index && stored_index.is_a?(Hash) if stored_index && stored_index.is_a?(Hash)
...@@ -101,7 +108,9 @@ module Pod ...@@ -101,7 +108,9 @@ module Pod
end end
File.open(search_index_path, 'w') {|f| f.write(search_index.to_yaml) } File.open(search_index_path, 'w') {|f| f.write(search_index.to_yaml) }
search_index @updated_search_index = search_index
end
@updated_search_index
end end
# @return [Pathname] The path where the search index should be stored. # @return [Pathname] The path where the search index should be stored.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment