Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2017-06-15 16:19:25 +0300
committerYorick Peterse <yorickpeterse@gmail.com>2017-06-19 20:11:35 +0300
commitc9e277ee01b05da7e359459a0a25bdd9bc7dbca8 (patch)
tree4edc9db2155f8dff7f17bc769784d17f966e196c /app/finders/projects_finder.rb
parent73bf9413b95d20860c09b3b37737c37add2d1342 (diff)
Refactor GroupProjectsFinder#init_collection
This optimises how GroupProjectsFinder builds it collection, producing simpler and faster queries in the process. It also cleans up the code a bit to make it easier to understand.
Diffstat (limited to 'app/finders/projects_finder.rb')
-rw-r--r--app/finders/projects_finder.rb18
1 files changed, 1 insertions, 17 deletions
diff --git a/app/finders/projects_finder.rb b/app/finders/projects_finder.rb
index 72e9c7a1cd7..8bfbe37c543 100644
--- a/app/finders/projects_finder.rb
+++ b/app/finders/projects_finder.rb
@@ -58,27 +58,11 @@ class ProjectsFinder < UnionFinder
if private_only?
current_user.authorized_projects
else
- collection_with_user_and_public_projects
+ Project.public_or_visible_to_user(current_user)
end
end
end
- # Builds a collection for a signed in user that includes additional projects
- # such as public and internal ones.
- #
- # This method manually constructs some WHERE conditions in order to ensure the
- # produced query is as efficient as possible.
- def collection_with_user_and_public_projects
- levels = Gitlab::VisibilityLevel.levels_for_user(current_user)
- authorized = current_user.project_authorizations.
- select(1).
- where('project_id = projects.id')
-
- Project.where('EXISTS (?) OR projects.visibility_level IN (?)',
- authorized,
- levels)
- end
-
# Builds a collection for an anonymous user.
def collection_without_user
if private_only? || owned_projects?