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
Jérome Perrin
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
Hide 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
# Returns a collection of projects that is either public or visible to the
# 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.
# This is useful for performance as we can stick those additional filters
# at the bottom of e.g. the UNION.
def
projects_for_user
(
&
block
)
return
block
.
call
(
Project
.
public_to_user
)
unless
current_user
def
projects_for_user
return
yield
(
Project
.
public_to_user
)
unless
current_user
# If the current_user is allowed to see all projects,
# 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
.
project_authorizations
.
select
(
1
)
.
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
)
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
# 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