diff options
author | Douwe Maan <douwe@gitlab.com> | 2017-08-15 08:06:37 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2017-08-15 08:06:37 +0000 |
commit | ef0e3c8e207f16ba1b923ad26d74e0099565275e (patch) | |
tree | 295c3853272bdcd00eb8fa3f54ebc869af4fe57e /app/models/member.rb | |
parent | b70ae21416a4519b0794ae546021800187aabcd6 (diff) | |
parent | d7b03c37f8346e29f21f0196fd3a532effa60ec3 (diff) | |
download | gitlab-ce-ef0e3c8e207f16ba1b923ad26d74e0099565275e.tar.gz |
Merge branch '34533-speed-up-group-project-authorizations' into 'master'
Speed up Group#user_ids_for_project_authorizations
Closes #36182
See merge request !13508
Diffstat (limited to 'app/models/member.rb')
-rw-r--r-- | app/models/member.rb | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/app/models/member.rb b/app/models/member.rb index b26b5017183..ee2cb13697b 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -41,9 +41,20 @@ class Member < ActiveRecord::Base is_external_invite = arel_table[:user_id].eq(nil).and(arel_table[:invite_token].not_eq(nil)) user_is_active = User.arel_table[:state].eq(:active) - includes(:user).references(:users) - .where(is_external_invite.or(user_is_active)) + user_ok = Arel::Nodes::Grouping.new(is_external_invite).or(user_is_active) + + left_join_users + .where(user_ok) + .where(requested_at: nil) + .reorder(nil) + end + + # Like active, but without invites. For when a User is required. + scope :active_without_invites, -> do + left_join_users + .where(users: { state: 'active' }) .where(requested_at: nil) + .reorder(nil) end scope :invite, -> { where.not(invite_token: nil) } |