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
8a1c3b6e
Commit
8a1c3b6e
authored
Nov 25, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add latest changes from gitlab-org/gitlab@master
parent
33c89fa9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletion
+30
-1
app/finders/projects_finder.rb
app/finders/projects_finder.rb
+25
-1
changelogs/unreleased/projects_finder_visibility_optimization.yml
...gs/unreleased/projects_finder_visibility_optimization.yml
+5
-0
No files found.
app/finders/projects_finder.rb
View file @
8a1c3b6e
...
...
@@ -79,7 +79,7 @@ class ProjectsFinder < UnionFinder
elsif
min_access_level?
current_user
.
authorized_projects
(
params
[
:min_access_level
])
else
if
private_only?
if
private_only?
||
impossible_visibility_level?
current_user
.
authorized_projects
else
Project
.
public_or_visible_to_user
(
current_user
)
...
...
@@ -96,6 +96,30 @@ class ProjectsFinder < UnionFinder
end
end
# This is an optimization - surprisingly PostgreSQL does not optimize
# for this.
#
# If the default visiblity level and desired visiblity level filter cancels
# each other out, don't use the SQL clause for visibility level in
# `Project.public_or_visible_to_user`. In fact, this then becames equivalent
# to just authorized projects for the user.
#
# E.g.
# (EXISTS(<authorized_projects>) OR projects.visibility_level IN (10,20))
# AND "projects"."visibility_level" = 0
#
# is essentially
# EXISTS(<authorized_projects>) AND "projects"."visibility_level" = 0
#
# See https://gitlab.com/gitlab-org/gitlab/issues/37007
def
impossible_visibility_level?
return
unless
params
[
:visibility_level
].
present?
public_visibility_levels
=
Gitlab
::
VisibilityLevel
.
levels_for_user
(
current_user
)
!
public_visibility_levels
.
include?
(
params
[
:visibility_level
])
end
def
owned_projects?
params
[
:owned
].
present?
end
...
...
changelogs/unreleased/projects_finder_visibility_optimization.yml
0 → 100644
View file @
8a1c3b6e
---
title
:
Optimize query when Projects API requests private visibility level
merge_request
:
20594
author
:
type
:
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