Commit d2c01d8a authored by Doug Stull's avatar Doug Stull Committed by Matthias Käppler

Use SafeRequestLoader to dry up logic in contribution check

parent 2b592225
...@@ -198,31 +198,15 @@ class ProjectTeam ...@@ -198,31 +198,15 @@ class ProjectTeam
end end
def contribution_check_for_user_ids(user_ids) def contribution_check_for_user_ids(user_ids)
user_ids = user_ids.uniq Gitlab::SafeRequestLoader.execute(resource_key: "contribution_check_for_users:#{project.id}",
key = "contribution_check_for_users:#{project.id}" resource_ids: user_ids,
default_value: false) do |user_ids|
Gitlab::SafeRequestStore[key] ||= {} project.merge_requests
contributors = Gitlab::SafeRequestStore[key] || {}
user_ids -= contributors.keys
return contributors if user_ids.empty?
resource_contributors = project.merge_requests
.merged .merged
.where(author_id: user_ids, target_branch: project.default_branch.to_s) .where(author_id: user_ids, target_branch: project.default_branch.to_s)
.pluck(:author_id) .pluck(:author_id)
.product([true]).to_h .product([true]).to_h
contributors.merge!(resource_contributors)
missing_resource_ids = user_ids - resource_contributors.keys
missing_resource_ids.each do |resource_id|
contributors[resource_id] = false
end end
contributors
end end
def contributor?(user_id) def contributor?(user_id)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment