diff options
author | Douwe Maan <douwe@selenight.nl> | 2018-06-29 12:37:16 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2018-07-02 11:58:32 +0300 |
commit | 29e2e1888b30883644ecbab6ca63c9415a6ea3ac (patch) | |
tree | bebe24e3af554a122ed93e17050c671b59f0ef34 /app/models | |
parent | 50a213112ee422bea6673cf15a8c4829ac8700ee (diff) |
Improve performance of User.without_projects scope
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/user.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 8e0dc91b2a7..48629c58490 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -244,7 +244,7 @@ class User < ActiveRecord::Base scope :blocked, -> { with_states(:blocked, :ldap_blocked) } scope :external, -> { where(external: true) } scope :active, -> { with_state(:active).non_internal } - scope :without_projects, -> { where('id NOT IN (SELECT DISTINCT(user_id) FROM members WHERE user_id IS NOT NULL AND requested_at IS NULL)') } + scope :without_projects, -> { joins('LEFT JOIN project_authorizations ON users.id = project_authorizations.user_id').where(project_authorizations: { user_id: nil }) } scope :todo_authors, ->(user_id, state) { where(id: Todo.where(user_id: user_id, state: state).select(:author_id)) } scope :order_recent_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'DESC')) } scope :order_oldest_sign_in, -> { reorder(Gitlab::Database.nulls_last_order('current_sign_in_at', 'ASC')) } |