summaryrefslogtreecommitdiff
path: root/app/models/member.rb
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2017-08-11 15:19:11 +0100
committerNick Thomas <nick@gitlab.com>2017-08-14 12:47:15 +0100
commitd7b03c37f8346e29f21f0196fd3a532effa60ec3 (patch)
treedae0a75f4dd508f2531788247d8bac88e0484162 /app/models/member.rb
parent455dc74e65e7461c1a51bf3ea6594fe20b9df90c (diff)
downloadgitlab-ce-d7b03c37f8346e29f21f0196fd3a532effa60ec3.tar.gz
Speed up Group#user_ids_for_project_authorizations
Diffstat (limited to 'app/models/member.rb')
-rw-r--r--app/models/member.rb15
1 files changed, 13 insertions, 2 deletions
diff --git a/app/models/member.rb b/app/models/member.rb
index dc9247bc9a0..17e343c84d8 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) }