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:
parent
954968c684
commit
77d4546eda
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue