diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2018-05-17 16:02:07 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2018-05-28 13:52:37 +0200 |
commit | 77d4546eda74d58e32a3f49aaa9935d6b8d1e526 (patch) | |
tree | f166b3486ac250fd7f2734c7af2f0a977f2f21b2 /app/finders | |
parent | 954968c684d12a58b265c9e3796faddc84edd400 (diff) | |
download | gitlab-ce-77d4546eda74d58e32a3f49aaa9935d6b8d1e526.tar.gz |
Reduce queries in GroupProjectsFinder
GroupProjectsFinder#collection_with_user would run the following code:
if group.users.include?(current_user)
When running this code for multiple groups this would result in one
query being executed for every group.
This commit simple removes the entire "if" statement with the code of
the "else" statement. This ensures both paths use the same code, and
removes the need for explicitly checking if a user is a member of the
group.
Diffstat (limited to 'app/finders')
-rw-r--r-- | app/finders/group_projects_finder.rb | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/app/finders/group_projects_finder.rb b/app/finders/group_projects_finder.rb index f73cf8adb4d..b6bdb2b7b0f 100644 --- a/app/finders/group_projects_finder.rb +++ b/app/finders/group_projects_finder.rb @@ -39,25 +39,15 @@ class GroupProjectsFinder < ProjectsFinder end def collection_with_user - if group.users.include?(current_user) - if only_shared? - [shared_projects] - elsif only_owned? - [owned_projects] - else - [shared_projects, owned_projects] - end + if only_shared? + [shared_projects.public_or_visible_to_user(current_user)] + elsif only_owned? + [owned_projects.public_or_visible_to_user(current_user)] else - if only_shared? - [shared_projects.public_or_visible_to_user(current_user)] - elsif only_owned? - [owned_projects.public_or_visible_to_user(current_user)] - else - [ - owned_projects.public_or_visible_to_user(current_user), - shared_projects.public_or_visible_to_user(current_user) - ] - end + [ + owned_projects.public_or_visible_to_user(current_user), + shared_projects.public_or_visible_to_user(current_user) + ] end end |