diff options
author | Fire Demon <firedemon@creature.cafe> | 2020-09-07 19:05:37 -0500 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-09-08 03:37:07 -0500 |
commit | 57f74d8da4f4906fde07caa6cb05cbb824edcbc4 (patch) | |
tree | d90c6c273cab6f31b3a93d428c15903025fade51 /app/models | |
parent | c05f4a88260e5aeb75be6a4121e812f6669e52b4 (diff) |
[Database, Models] Add indexes to users.username and User.find_by_lower_username utility methods
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/user.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 6fa6bb369..d20922993 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -101,6 +101,7 @@ class User < ApplicationRecord scope :matches_email, ->(value) { where(arel_table[:email].matches("#{value}%")) } scope :matches_ip, ->(value) { left_joins(:session_activations).where('users.current_sign_in_ip <<= ?', value).or(left_joins(:session_activations).where('users.last_sign_in_ip <<= ?', value)).or(left_joins(:session_activations).where('session_activations.ip <<= ?', value)) } scope :emailable, -> { confirmed.enabled.joins(:account).merge(Account.searchable) } + scope :lower_username, ->(username) { where('lower(users.username) = lower(?)', username) } before_validation :sanitize_languages before_create :set_approved @@ -465,4 +466,14 @@ class User < ApplicationRecord value = [account.username, username.downcase, email, invite_request.text].compact.map(&:downcase).join("\u{F0666}") Digest::SHA512.hexdigest(value).upcase end + + class << self + def find_by_lower_username(username) + lower_username(username).first + end + + def find_by_lower_username!(username) + lower_username(username).first! + end + end end |