Commit 4ec30fdd authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents ea11a86f 95838fe4
# frozen_string_literal: true
class GroupMembersFinder
class GroupMembersFinder < UnionFinder
def initialize(group)
@group = group
end
......@@ -8,18 +8,18 @@ class GroupMembersFinder
# rubocop: disable CodeReuse/ActiveRecord
def execute(include_descendants: false)
group_members = @group.members
wheres = []
relations = []
return group_members unless @group.parent || include_descendants
wheres << "members.id IN (#{group_members.select(:id).to_sql})"
relations << group_members
if @group.parent
parents_members = GroupMember.non_request
.where(source_id: @group.ancestors.select(:id))
.where.not(user_id: @group.users.select(:id))
wheres << "members.id IN (#{parents_members.select(:id).to_sql})"
relations << parents_members
end
if include_descendants
......@@ -27,10 +27,10 @@ class GroupMembersFinder
.where(source_id: @group.descendants.select(:id))
.where.not(user_id: @group.users.select(:id))
wheres << "members.id IN (#{descendant_members.select(:id).to_sql})"
relations << descendant_members
end
GroupMember.where(wheres.join(' OR '))
find_union(relations, GroupMember)
end
# rubocop: enable CodeReuse/ActiveRecord
end
......
# frozen_string_literal: true
class GroupMember < Member
include FromUnion
SOURCE_TYPE = 'Namespace'.freeze
belongs_to :group, foreign_key: 'source_id'
......
---
title: Improve MembersFinder query performance using UNION
merge_request: 30451
author: Jacopo Beschi @jacopo-beschi
type: performance
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