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.
This commit is contained in:
Yorick Peterse 2018-05-17 16:02:07 +02:00
parent 954968c684
commit 77d4546eda
No known key found for this signature in database
GPG Key ID: EDD30D2BEB691AC9
1 changed files with 8 additions and 18 deletions

View File

@ -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