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
47c1a175
Commit
47c1a175
authored
Jul 08, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve snippet finders query
parent
deda7b39
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
2 deletions
+32
-2
app/finders/snippets_finder.rb
app/finders/snippets_finder.rb
+12
-1
changelogs/unreleased/fj-227311-optimize-snippets-finder-query.yml
...s/unreleased/fj-227311-optimize-snippets-finder-query.yml
+5
-0
ee/app/finders/ee/snippets_finder.rb
ee/app/finders/ee/snippets_finder.rb
+1
-1
ee/spec/finders/snippets_finder_spec.rb
ee/spec/finders/snippets_finder_spec.rb
+8
-0
spec/finders/snippets_finder_spec.rb
spec/finders/snippets_finder_spec.rb
+6
-0
No files found.
app/finders/snippets_finder.rb
View file @
47c1a175
...
...
@@ -117,7 +117,7 @@ class SnippetsFinder < UnionFinder
queries
<<
snippets_of_authorized_projects
if
current_user
end
find_union
(
queries
,
Snippet
)
prepared_union
(
queries
)
end
def
snippets_for_a_single_project
...
...
@@ -208,6 +208,17 @@ class SnippetsFinder < UnionFinder
def
sort_param
sort
.
presence
||
'id_desc'
end
def
prepared_union
(
queries
)
return
Snippet
.
none
if
queries
.
empty?
return
queries
.
first
if
queries
.
length
==
1
# The queries are going to be part of a global `where`
# therefore we only need to retrieve the `id` column
# which will speed the query
queries
.
map!
{
|
rel
|
rel
.
select
(
:id
)
}
Snippet
.
id_in
(
find_union
(
queries
,
Snippet
))
end
end
SnippetsFinder
.
prepend_if_ee
(
'EE::SnippetsFinder'
)
changelogs/unreleased/fj-227311-optimize-snippets-finder-query.yml
0 → 100644
View file @
47c1a175
---
title
:
Improve snippet finders queries
merge_request
:
36292
author
:
type
:
performance
ee/app/finders/ee/snippets_finder.rb
View file @
47c1a175
...
...
@@ -34,7 +34,7 @@ module EE
queries
<<
snippets_of_authorized_projects
unless
only_personal
end
find_union
(
queries
,
::
Snippet
)
prepared_union
(
queries
)
end
def
restricted_personal_snippets
...
...
ee/spec/finders/snippets_finder_spec.rb
View file @
47c1a175
...
...
@@ -181,6 +181,14 @@ RSpec.describe SnippetsFinder do
private_project_snippet
)
end
context
'when no personal snippets are visible'
do
let
(
:user
)
{
nil
}
it
'does not return any record'
do
expect
(
subject
).
to
be_empty
end
end
end
end
end
spec/finders/snippets_finder_spec.rb
View file @
47c1a175
...
...
@@ -283,6 +283,12 @@ RSpec.describe SnippetsFinder do
it
'returns only personal snippets when the user cannot read cross project'
do
expect
(
described_class
.
new
(
user
).
execute
).
to
contain_exactly
(
private_personal_snippet
,
internal_personal_snippet
,
public_personal_snippet
)
end
context
'when only project snippets are required'
do
it
'returns no records'
do
expect
(
described_class
.
new
(
user
,
only_project:
true
).
execute
).
to
be_empty
end
end
end
context
'when project snippets are disabled'
do
...
...
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