Skip to content

A platform for community discussion. Free, open, simple.

PERF: Query for email was not using index.

Guo Xiang Tan65eb046e6988
diff --git a/app/models/user.rb b/app/models/user.rb
index 0ac14d77a19..6ae9ef16c23 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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)::text = ?", email)
+ end
scope :human_users, -> { where('users.id > 0') }