Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
2c8ce4f6
Commit
2c8ce4f6
authored
Apr 10, 2013
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[SourcesManager] Improve search performance
parent
3fe56ec1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
19 deletions
+28
-19
sources_manager.rb
lib/cocoapods/sources_manager.rb
+28
-19
No files found.
lib/cocoapods/sources_manager.rb
View file @
2c8ce4f6
...
@@ -59,18 +59,21 @@ module Pod
...
@@ -59,18 +59,21 @@ 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
)
set_names
=
[]
if
full_text_search
updated_search_index
.
each
do
|
name
,
set_data
|
set_names
=
[]
text
=
name
.
dup
updated_search_index
.
each
do
|
name
,
set_data
|
if
full_text_search
text
=
name
.
dup
text
<<
set_data
[
'authors'
].
to_s
if
set_data
[
'authors'
]
if
full_text_search
text
<<
set_data
[
'summary'
]
if
set_data
[
'summary'
]
text
<<
set_data
[
'authors'
].
to_s
if
set_data
[
'authors'
]
text
<<
set_data
[
'description'
]
if
set_data
[
'description'
]
text
<<
set_data
[
'summary'
]
if
set_data
[
'summary'
]
text
<<
set_data
[
'description'
]
if
set_data
[
'description'
]
end
set_names
<<
name
if
text
.
downcase
.
include?
(
query
.
downcase
)
end
end
set_names
<<
name
if
text
.
downcase
.
include?
(
query
.
downcase
)
sets
=
set_names
.
sort
.
map
{
|
name
|
aggregate
.
represenative_set
(
name
)
}
else
sets
=
aggregate
.
search_by_name
(
query
,
false
)
end
end
sets
=
set_names
.
sort
.
map
{
|
name
|
aggregate
.
represenative_set
(
name
)
}
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,22 +89,28 @@ module Pod
...
@@ -86,22 +89,28 @@ 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
if
search_index_path
.
exist?
unless
@updated_search_index
stored_index
=
YAML
.
load
(
search_index_path
.
read
)
if
search_index_path
.
exist?
if
stored_index
&&
stored_index
.
is_a?
(
Hash
)
stored_index
=
YAML
.
load
(
search_index_path
.
read
)
search_index
=
aggregate
.
update_search_index
(
stored_index
)
if
stored_index
&&
stored_index
.
is_a?
(
Hash
)
search_index
=
aggregate
.
update_search_index
(
stored_index
)
else
search_index
=
aggregate
.
generate_search_index
end
else
else
search_index
=
aggregate
.
generate_search_index
search_index
=
aggregate
.
generate_search_index
end
end
else
search_index
=
aggregate
.
generate_search_index
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.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment