From c9e277ee01b05da7e359459a0a25bdd9bc7dbca8 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 15 Jun 2017 15:19:25 +0200 Subject: 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. --- app/finders/projects_finder.rb | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) (limited to 'app/finders/projects_finder.rb') 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? -- cgit v1.2.3