Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
8216e0be
Commit
8216e0be
authored
Jan 09, 2020
by
Mark Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unused `FoundBlob` wrapping on view and API
Project batch loading is done in search layer.
parent
0130f678
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
3 additions
and
123 deletions
+3
-123
app/helpers/search_helper.rb
app/helpers/search_helper.rb
+0
-13
app/views/search/_results.html.haml
app/views/search/_results.html.haml
+1
-2
app/views/search/results/_blob.html.haml
app/views/search/results/_blob.html.haml
+1
-3
app/views/search/results/_wiki_blob.html.haml
app/views/search/results/_wiki_blob.html.haml
+1
-2
ee/app/helpers/ee/search_helper.rb
ee/app/helpers/ee/search_helper.rb
+0
-27
ee/lib/ee/api/search.rb
ee/lib/ee/api/search.rb
+0
-11
ee/spec/helpers/search_helper_spec.rb
ee/spec/helpers/search_helper_spec.rb
+0
-61
lib/api/search.rb
lib/api/search.rb
+0
-4
No files found.
app/helpers/search_helper.rb
View file @
8216e0be
...
...
@@ -86,19 +86,6 @@ module SearchHelper
}).
html_safe
end
def
find_project_for_result_blob
(
projects
,
result
)
@project
end
# Used in EE
def
blob_projects
(
results
)
nil
end
def
parse_search_result
(
result
)
result
end
# Overriden in EE
def
search_blob_title
(
project
,
path
)
path
...
...
app/views/search/_results.html.haml
View file @
8216e0be
...
...
@@ -32,8 +32,7 @@
.term
=
render
'shared/projects/list'
,
projects:
@search_objects
,
pipeline_status:
false
-
else
-
locals
=
{
projects:
blob_projects
(
@search_objects
)
}
if
%w[blobs wiki_blobs]
.
include?
(
@scope
)
=
render
partial:
"search/results/
#{
@scope
.
singularize
}
"
,
collection:
@search_objects
,
locals:
locals
=
render
partial:
"search/results/
#{
@scope
.
singularize
}
"
,
collection:
@search_objects
-
if
@scope
!=
'projects'
=
paginate_collection
(
@search_objects
)
app/views/search/results/_blob.html.haml
View file @
8216e0be
-
project
=
find_project_for_result_blob
(
projects
,
blob
)
-
project
=
blob
.
project
-
return
unless
project
-
blob
=
parse_search_result
(
blob
)
-
blob_link
=
project_blob_path
(
project
,
tree_join
(
blob
.
ref
,
blob
.
path
))
=
render
partial:
'search/results/blob_data'
,
locals:
{
blob:
blob
,
project:
project
,
path:
blob
.
path
,
blob_link:
blob_link
}
app/views/search/results/_wiki_blob.html.haml
View file @
8216e0be
-
project
=
find_project_for_result_blob
(
projects
,
wiki_blob
)
-
wiki_blob
=
parse_search_result
(
wiki_blob
)
-
project
=
wiki_blob
.
project
-
wiki_blob_link
=
project_wiki_path
(
project
,
wiki_blob
.
basename
)
=
render
partial:
'search/results/blob_data'
,
locals:
{
blob:
wiki_blob
,
project:
project
,
path:
wiki_blob
.
path
,
blob_link:
wiki_blob_link
}
ee/app/helpers/ee/search_helper.rb
View file @
8216e0be
...
...
@@ -13,29 +13,6 @@ module EE
options
end
override
:find_project_for_result_blob
def
find_project_for_result_blob
(
projects
,
result
)
return
super
if
result
.
is_a?
(
::
Gitlab
::
Search
::
FoundBlob
)
super
||
projects
&
.
find
{
|
project
|
project
.
id
==
blob_project_id
(
result
)
}
end
override
:blob_projects
def
blob_projects
(
results
)
return
super
if
results
.
first
.
is_a?
(
::
Gitlab
::
Search
::
FoundBlob
)
project_ids
=
results
.
map
(
&
method
(
:blob_project_id
))
::
ProjectsFinder
.
new
(
current_user:
current_user
,
project_ids_relation:
project_ids
).
execute
end
override
:parse_search_result
def
parse_search_result
(
result
)
return
super
if
result
.
is_a?
(
::
Gitlab
::
Search
::
FoundBlob
)
::
Gitlab
::
Elastic
::
SearchResults
.
parse_search_result
(
result
)
end
override
:search_blob_title
def
search_blob_title
(
project
,
path
)
if
@project
...
...
@@ -88,10 +65,6 @@ module EE
context
.
feature_available?
(
:multiple_issue_assignees
))
end
def
blob_project_id
(
blob_result
)
blob_result
.
dig
(
'_source'
,
'join_field'
,
'parent'
)
&
.
split
(
'_'
)
&
.
last
.
to_i
end
def
gitlab_com_snippet_db_search?
@current_user
&&
@show_snippets
&&
...
...
ee/lib/ee/api/search.rb
View file @
8216e0be
...
...
@@ -21,17 +21,6 @@ module EE
def
use_elasticsearch?
(
resource
)
::
Gitlab
::
CurrentSettings
.
search_using_elasticsearch?
(
scope:
resource
)
end
override
:process_results
def
process_results
(
results
)
return
[]
if
results
.
empty?
if
results
.
any?
{
|
result
|
result
.
is_a?
(
::
Elasticsearch
::
Model
::
Response
::
Result
)
&&
result
.
respond_to?
(
:blob
)
}
return
paginate
(
results
).
map
{
|
blob
|
::
Gitlab
::
Elastic
::
SearchResults
.
parse_search_result
(
blob
)
}
end
super
end
end
end
end
...
...
ee/spec/helpers/search_helper_spec.rb
View file @
8216e0be
...
...
@@ -51,67 +51,6 @@ describe SearchHelper do
end
end
describe
'#parse_search_result with elastic enabled'
,
:elastic
do
let
(
:user
)
{
create
(
:user
)
}
before
do
allow
(
self
).
to
receive
(
:current_user
).
and_return
(
user
)
stub_ee_application_setting
(
elasticsearch_search:
true
,
elasticsearch_indexing:
true
)
end
it
"returns parsed result"
,
:sidekiq_might_not_need_inline
do
project
=
create
:project
,
:repository
project
.
repository
.
index_commits_and_blobs
Gitlab
::
Elastic
::
Helper
.
refresh_index
result
=
project
.
repository
.
elastic_search
(
'def popen'
,
type: :blob
,
options:
{
highlight:
true
}
)[
:blobs
][
:results
][
0
]
parsed_result
=
helper
.
parse_search_result
(
result
)
expect
(
parsed_result
.
ref
).
to
eq
(
'b83d6e391c22777fca1ed3012fce84f633d7fed0'
)
expect
(
parsed_result
.
path
).
to
eq
(
'files/ruby/popen.rb'
)
expect
(
parsed_result
.
startline
).
to
eq
(
2
)
expect
(
parsed_result
.
data
).
to
include
(
"Popen"
)
end
end
describe
'#blob_projects'
,
:elastic
do
let
(
:user
)
{
create
(
:user
)
}
before
do
allow
(
self
).
to
receive
(
:current_user
).
and_return
(
user
)
stub_ee_application_setting
(
elasticsearch_search:
true
,
elasticsearch_indexing:
true
)
end
def
es_blob_search
Repository
.
elastic_search
(
'def popen'
,
type: :blob
,
options:
{
highlight:
true
}
)[
:blobs
][
:results
]
end
it
'returns all projects in the result page without causing an N+1'
,
:sidekiq_might_not_need_inline
do
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
blob_projects
(
es_blob_search
)
}.
count
projects
=
create_list
:project
,
3
,
:repository
,
:public
projects
.
each
{
|
project
|
project
.
repository
.
index_commits_and_blobs
}
Gitlab
::
Elastic
::
Helper
.
refresh_index
# So we can access it outside the following block
result_projects
=
nil
expect
{
result_projects
=
blob_projects
(
es_blob_search
)
}.
not_to
exceed_query_limit
(
control_count
)
expect
(
result_projects
).
to
match_array
(
projects
)
end
end
describe
'#search_entries_info_template'
do
let
(
:com_value
)
{
true
}
let
(
:flag_enabled
)
{
true
}
...
...
lib/api/search.rb
View file @
8216e0be
...
...
@@ -32,10 +32,6 @@ module API
results
=
SearchService
.
new
(
current_user
,
search_params
).
search_objects
process_results
(
results
)
end
def
process_results
(
results
)
paginate
(
results
)
end
...
...
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