diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-15 13:41:17 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2015-10-15 13:41:17 +0000 |
commit | 5ce933599c1c1407620a340de4947497576ad12a (patch) | |
tree | c12c26b807c314cd004d8ddebda0aa1421aa5ec5 /app | |
parent | c0a6836be48bdf9a32ac2c9e610f62aef1e2e3f7 (diff) | |
parent | 72f428c7d217a5c40ed87d68ab9100e4c8754633 (diff) | |
download | gitlab-ce-5ce933599c1c1407620a340de4947497576ad12a.tar.gz |
Merge branch 'user-by-login-performance' into 'master'
Improve User.by_login performance
This greatly speeds up the performance of `User.by_login`. I adopted some changes from @haynes in this patch, the credits go to him for coming up with those originally.
Fixes #2341
See merge request !1545
Diffstat (limited to 'app')
-rw-r--r-- | app/models/user.rb | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 889d2d3b867..17ccb3b8788 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -68,6 +68,7 @@ class User < ActiveRecord::Base include Referable include Sortable include TokenAuthenticatable + include CaseSensitivity default_value_for :admin, false default_value_for :can_create_group, gitlab_config.default_can_create_group @@ -273,8 +274,13 @@ class User < ActiveRecord::Base end def by_login(login) - where('lower(username) = :value OR lower(email) = :value', - value: login.to_s.downcase).first + return nil unless login + + if login.include?('@'.freeze) + unscoped.iwhere(email: login).take + else + unscoped.iwhere(username: login).take + end end def find_by_username!(username) |