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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
0a3fc7e3
Commit
0a3fc7e3
authored
Mar 02, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use yield instead of block.call.
parent
82a32e27
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
6 deletions
+6
-6
app/finders/snippets_finder.rb
app/finders/snippets_finder.rb
+6
-6
No files found.
app/finders/snippets_finder.rb
View file @
0a3fc7e3
...
@@ -61,25 +61,25 @@ class SnippetsFinder < UnionFinder
...
@@ -61,25 +61,25 @@ class SnippetsFinder < UnionFinder
# Returns a collection of projects that is either public or visible to the
# Returns a collection of projects that is either public or visible to the
# logged in user.
# logged in user.
#
#
# A caller m
ay
pass in a block to modify individual parts of
# A caller m
ust
pass in a block to modify individual parts of
# the query, e.g. to apply .with_feature_available_for_user on top of it.
# the query, e.g. to apply .with_feature_available_for_user on top of it.
# This is useful for performance as we can stick those additional filters
# This is useful for performance as we can stick those additional filters
# at the bottom of e.g. the UNION.
# at the bottom of e.g. the UNION.
def
projects_for_user
(
&
block
)
def
projects_for_user
return
block
.
call
(
Project
.
public_to_user
)
unless
current_user
return
yield
(
Project
.
public_to_user
)
unless
current_user
# If the current_user is allowed to see all projects,
# If the current_user is allowed to see all projects,
# we can shortcut and just return.
# we can shortcut and just return.
return
block
.
call
(
Project
.
all
)
if
current_user
.
full_private_access?
return
yield
(
Project
.
all
)
if
current_user
.
full_private_access?
authorized
=
current_user
authorized
=
current_user
.
project_authorizations
.
project_authorizations
.
select
(
1
)
.
select
(
1
)
.
where
(
'project_authorizations.project_id = projects.id'
)
.
where
(
'project_authorizations.project_id = projects.id'
)
authorized_projects
=
block
.
call
(
Project
.
where
(
'EXISTS (?)'
,
authorized
))
authorized_projects
=
yield
(
Project
.
where
(
'EXISTS (?)'
,
authorized
))
levels
=
Gitlab
::
VisibilityLevel
.
levels_for_user
(
current_user
)
levels
=
Gitlab
::
VisibilityLevel
.
levels_for_user
(
current_user
)
visible_projects
=
block
.
call
(
Project
.
where
(
visibility_level:
levels
))
visible_projects
=
yield
(
Project
.
where
(
visibility_level:
levels
))
# We use a UNION here instead of OR clauses since this results in better
# We use a UNION here instead of OR clauses since this results in better
# performance.
# performance.
...
...
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