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
37551527
Commit
37551527
authored
Jun 12, 2019
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Restore some unrelated changes from
d9cb907c
parent
7c0beb47
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
75 additions
and
7 deletions
+75
-7
app/views/search/results/_issue.html.haml
app/views/search/results/_issue.html.haml
+1
-1
app/views/search/results/_merge_request.html.haml
app/views/search/results/_merge_request.html.haml
+1
-1
app/views/search/results/_milestone.html.haml
app/views/search/results/_milestone.html.haml
+1
-1
ee/app/models/concerns/elastic/milestones_search.rb
ee/app/models/concerns/elastic/milestones_search.rb
+1
-1
ee/changelogs/unreleased/10854-elasticsearch_avoid_db.yml
ee/changelogs/unreleased/10854-elasticsearch_avoid_db.yml
+5
-0
ee/spec/features/search/elastic/global_search_spec.rb
ee/spec/features/search/elastic/global_search_spec.rb
+65
-3
ee/spec/models/concerns/elastic/milestone_spec.rb
ee/spec/models/concerns/elastic/milestone_spec.rb
+1
-0
No files found.
app/views/search/results/_issue.html.haml
View file @
37551527
.search-result-row
%h4
=
confidential_icon
(
issue
)
=
link_to
[
issue
.
project
.
namespace
.
becomes
(
Namespace
),
issue
.
project
,
issue
]
do
=
link_to
namespace_project_issue_path
(
issue
.
project
.
namespace
.
becomes
(
Namespace
),
issue
.
project
,
issue
)
do
%span
.term.str-truncated
=
issue
.
title
-
if
issue
.
closed?
%span
.badge.badge-danger.prepend-left-5
=
_
(
"Closed"
)
...
...
app/views/search/results/_merge_request.html.haml
View file @
37551527
.search-result-row
%h4
=
link_to
[
merge_request
.
target_project
.
namespace
.
becomes
(
Namespace
),
merge_request
.
target_project
,
merge_request
]
do
=
link_to
namespace_project_merge_request_path
(
merge_request
.
target_project
.
namespace
.
becomes
(
Namespace
),
merge_request
.
target_project
,
merge_request
)
do
%span
.term.str-truncated
=
merge_request
.
title
-
if
merge_request
.
merged?
%span
.badge.badge-primary.prepend-left-5
=
_
(
"Merged"
)
...
...
app/views/search/results/_milestone.html.haml
View file @
37551527
.search-result-row
%h4
=
link_to
[
milestone
.
project
.
namespace
.
becomes
(
Namespace
),
milestone
.
project
,
milestone
]
do
=
link_to
namespace_project_milestone_path
(
milestone
.
project
.
namespace
.
becomes
(
Namespace
),
milestone
.
project
,
milestone
)
do
%span
.term.str-truncated
=
milestone
.
title
-
if
milestone
.
description
.
present?
...
...
ee/app/models/concerns/elastic/milestones_search.rb
View file @
37551527
...
...
@@ -12,7 +12,7 @@ module Elastic
# https://gitlab.com/gitlab-org/gitlab-ee/issues/349
data
=
{}
[
:id
,
:title
,
:description
,
:project_id
,
:created_at
,
:updated_at
].
each
do
|
attr
|
[
:id
,
:
iid
,
:
title
,
:description
,
:project_id
,
:created_at
,
:updated_at
].
each
do
|
attr
|
data
[
attr
.
to_s
]
=
safely_read_attribute_for_elasticsearch
(
attr
)
end
...
...
ee/changelogs/unreleased/10854-elasticsearch_avoid_db.yml
0 → 100644
View file @
37551527
---
title
:
Avoid loading database objects for Elasticsearch results
merge_request
:
12691
author
:
type
:
performance
ee/spec/features/search/elastic/global_search_spec.rb
View file @
37551527
require
'spec_helper'
describe
'Global elastic search'
do
describe
'Global elastic search'
,
:elastic
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
,
:repository
,
:wiki_repo
,
namespace:
user
.
namespace
)
}
before
do
stub_ee_application_setting
(
elasticsearch_search:
true
,
elasticsearch_indexing:
true
)
Gitlab
::
Elastic
::
Helper
.
create_empty_index
project
.
add_maintainer
(
user
)
sign_in
(
user
)
end
after
do
Gitlab
::
Elastic
::
Helper
.
delete_index
stub_ee_application_setting
(
elasticsearch_search:
false
,
elasticsearch_indexing:
false
)
end
shared_examples
'a pure Elasticsearch result'
do
it
'avoids N+1 database queries'
do
create
(
object
,
creation_args
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
visit
path
}.
count
create_list
(
object
,
10
,
creation_args
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
control_count
=
control_count
+
(
10
*
query_count_multiplier
)
+
1
expect
{
visit
path
}.
not_to
exceed_query_limit
(
control_count
)
end
end
describe
'I do not overload the database'
do
context
'searching issues'
do
let
(
:object
)
{
:issue
}
let
(
:creation_args
)
{
{
project:
project
,
title:
'initial'
}
}
let
(
:path
)
{
search_path
(
search:
'initial'
,
scope:
'issues'
)
}
let
(
:query_count_multiplier
)
{
0
}
it_behaves_like
'a pure Elasticsearch result'
end
context
'searching projects'
do
let
(
:object
)
{
:project
}
let
(
:creation_args
)
{
{
namespace:
user
.
namespace
}
}
let
(
:path
)
{
search_path
(
search:
'project*'
,
scope:
'projects'
)
}
# Each Project requires 4 extra queries: one for each "count" (forks, open MRs, open Issues) and one for access level
let
(
:query_count_multiplier
)
{
4
}
it_behaves_like
'a pure Elasticsearch result'
end
context
'searching merge requests'
do
it
'avoids N+1 database queries'
do
path
=
search_path
(
search:
'initial'
,
scope:
'merge_requests'
)
create
(
:merge_request
,
title:
'initial'
,
source_project:
project
)
Gitlab
::
Elastic
::
Helper
.
refresh_index
control_count
=
ActiveRecord
::
QueryRecorder
.
new
{
visit
path
}.
count
merge_requests
=
create_list
(
:merge_request
,
10
,
title:
'initial'
)
merge_requests
.
each
{
|
mr
|
mr
.
target_project
.
add_maintainer
(
user
)
}
Gitlab
::
Elastic
::
Helper
.
refresh_index
# Each MR loaded has a Route load that has been tricky to track down
expect
{
visit
path
}.
not_to
exceed_query_limit
(
control_count
+
11
)
end
end
context
'searching milestones'
do
let
(
:object
)
{
:milestone
}
let
(
:creation_args
)
{
{
project:
project
}
}
let
(
:path
)
{
search_path
(
search:
'milestone*'
,
scope:
'milestones'
)
}
let
(
:query_count_multiplier
)
{
0
}
it_behaves_like
'a pure Elasticsearch result'
end
end
describe
'I search through the issues and I see pagination'
do
before
do
create_list
(
:issue
,
21
,
project:
project
,
title:
'initial'
)
...
...
ee/spec/models/concerns/elastic/milestone_spec.rb
View file @
37551527
...
...
@@ -39,6 +39,7 @@ describe Milestone, :elastic do
expected_hash
=
milestone
.
attributes
.
extract!
(
'id'
,
'iid'
,
'title'
,
'description'
,
'project_id'
,
...
...
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