Improve performance of User.without_projects scope

This commit is contained in:
Douwe Maan 2018-06-29 11:37:16 +02:00
parent 50a213112e
commit 29e2e1888b
No known key found for this signature in database
GPG Key ID: 5976703F65143D36
2 changed files with 6 additions and 1 deletions

View File

@ -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')) }

View File

@ -0,0 +1,5 @@
---
title: Improve performance of listing users without projects
merge_request:
author:
type: performance