PERF: PG queries for the `UserEmail#email` column was not using the index.
This commit is contained in:
parent
f053e4cf37
commit
52b9af10a1
|
@ -15,7 +15,7 @@ class FinishInstallationController < ApplicationController
|
|||
email = params[:email].strip
|
||||
raise Discourse::InvalidParameters.new unless @allowed_emails.include?(email)
|
||||
|
||||
return redirect_confirm(email) if UserEmail.exists?(email: email)
|
||||
return redirect_confirm(email) if UserEmail.where("lower(email) = ?", email).exists?
|
||||
|
||||
@user.email = email
|
||||
@user.username = params[:username]
|
||||
|
|
|
@ -134,7 +134,9 @@ class User < ActiveRecord::Base
|
|||
# set to true to optimize creation and save for imports
|
||||
attr_accessor :import_mode
|
||||
|
||||
scope :with_email, ->(email) { joins(:user_emails).where(user_emails: { email: email }) }
|
||||
scope :with_email, ->(email) do
|
||||
joins(:user_emails).where("lower(user_emails.email) = ?", email)
|
||||
end
|
||||
|
||||
scope :human_users, -> { where('users.id > 0') }
|
||||
|
||||
|
|
|
@ -104,7 +104,7 @@ class AdminUserIndexQuery
|
|||
def filter_by_user_with_bypass(filter)
|
||||
if filter =~ /.+@.+/
|
||||
# probably an email so try the bypass
|
||||
user_id = UserEmail.where(email: filter.downcase).pluck(:user_id).first
|
||||
user_id = UserEmail.where("lower(email) = ?", filter.downcase).pluck(:user_id).first
|
||||
if user_id
|
||||
return @query.where('users.id = ?', user_id)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue