PERF: Speed up admin user list main query (#16412)
This drops the join with the emails table since primary emails is already on the users table. Makes query 10x faster on large (6M+ users) sites.
This commit is contained in:
parent
0f7b9878ff
commit
be519d2aec
|
@ -4,7 +4,7 @@ class AdminUserIndexQuery
|
||||||
|
|
||||||
def initialize(params = {}, klass = User, trust_levels = TrustLevel.levels)
|
def initialize(params = {}, klass = User, trust_levels = TrustLevel.levels)
|
||||||
@params = params
|
@params = params
|
||||||
@query = initialize_query_with_order(klass.joins(:primary_email))
|
@query = initialize_query_with_order(klass)
|
||||||
@trust_levels = trust_levels
|
@trust_levels = trust_levels
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ class AdminUserIndexQuery
|
||||||
|
|
||||||
if !custom_order.present?
|
if !custom_order.present?
|
||||||
if params[:query] == "active"
|
if params[:query] == "active"
|
||||||
order << "COALESCE(users.last_seen_at, to_date('1970-01-01', 'YYYY-MM-DD')) DESC"
|
order << "users.last_seen_at DESC NULLS LAST"
|
||||||
else
|
else
|
||||||
order << "users.created_at DESC"
|
order << "users.created_at DESC"
|
||||||
end
|
end
|
||||||
|
@ -93,7 +93,7 @@ class AdminUserIndexQuery
|
||||||
|
|
||||||
def filter_by_search
|
def filter_by_search
|
||||||
if params[:email].present?
|
if params[:email].present?
|
||||||
return @query.where('user_emails.email = ?', params[:email].downcase)
|
return @query.joins(:primary_email).where('user_emails.email = ?', params[:email].downcase)
|
||||||
end
|
end
|
||||||
|
|
||||||
filter = params[:filter]
|
filter = params[:filter]
|
||||||
|
|
Loading…
Reference in New Issue