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
336bc95e
Commit
336bc95e
authored
Feb 16, 2018
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Push feature-related query part up.
parent
5a5a33a9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
2 deletions
+30
-2
app/finders/snippets_finder.rb
app/finders/snippets_finder.rb
+1
-2
app/models/project.rb
app/models/project.rb
+29
-0
No files found.
app/finders/snippets_finder.rb
View file @
336bc95e
...
@@ -56,8 +56,7 @@ class SnippetsFinder < UnionFinder
...
@@ -56,8 +56,7 @@ class SnippetsFinder < UnionFinder
end
end
def
feature_available_projects
def
feature_available_projects
projects
=
Project
.
public_or_visible_to_user
(
current_user
)
projects
=
Project
.
public_or_visible_to_user_with_feature_available
(
current_user
,
:snippets
).
select
(
:id
)
.
with_feature_available_for_user
(
:snippets
,
current_user
).
select
(
:id
)
arel_query
=
Arel
::
Nodes
::
SqlLiteral
.
new
(
projects
.
to_sql
)
arel_query
=
Arel
::
Nodes
::
SqlLiteral
.
new
(
projects
.
to_sql
)
table
[
:project_id
].
in
(
arel_query
)
table
[
:project_id
].
in
(
arel_query
)
end
end
...
...
app/models/project.rb
View file @
336bc95e
...
@@ -343,6 +343,35 @@ class Project < ActiveRecord::Base
...
@@ -343,6 +343,35 @@ class Project < ActiveRecord::Base
end
end
end
end
# Combination of .public_or_visible_to_user AND .with_feature_available_for_user
# We duplicated this for (database) performance reasons to optimize the query.
def
self
.
public_or_visible_to_user_with_feature_available
(
user
,
feature
)
if
user
authorized
=
user
.
project_authorizations
.
select
(
1
)
.
where
(
'project_authorizations.project_id = projects.id'
)
levels
=
Gitlab
::
VisibilityLevel
.
levels_for_user
(
user
)
if
Gitlab
::
VisibilityLevel
.
all_levels?
(
levels
)
# If the user is allowed to see all projects,
# we can shortcut and just return.
return
all
.
with_feature_available_for_user
(
feature
,
user
)
end
authorized_projects
=
where
(
'EXISTS (?)'
,
authorized
).
with_feature_available_for_user
(
feature
,
user
).
select
(
:id
)
visible_projects
=
where
(
'visibility_level IN (?)'
,
levels
).
with_feature_available_for_user
(
feature
,
user
).
select
(
:id
)
# We use a UNION here instead of OR clauses since this results in better
# performance.
union
=
Gitlab
::
SQL
::
Union
.
new
([
authorized_projects
,
visible_projects
])
from
(
"(
#{
union
.
to_sql
}
) projects"
)
else
public_to_user
.
with_feature_available_for_user
(
feature
,
user
)
end
end
# project features may be "disabled", "internal" or "enabled". If "internal",
# project features may be "disabled", "internal" or "enabled". If "internal",
# they are only available to team members. This scope returns projects where
# they are only available to team members. This scope returns projects where
# the feature is either enabled, or internal with permission for the user.
# the feature is either enabled, or internal with permission for the user.
...
...
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