diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-10-04 18:03:10 +0200 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-10-04 22:33:14 +0200 |
commit | f8522ee5f5be14b4132c115cad43978c9fd39a55 (patch) | |
tree | 7bc729fb96bebd7ac897d4b847a3ce3142d0c8bf /app/models/user.rb | |
parent | 7887a3dafb6902cc39c831e307c48faf49f80b51 (diff) | |
download | gitlab-ce-f8522ee5f5be14b4132c115cad43978c9fd39a55.tar.gz |
Refactor Gitlab::Identifiertest-improve-gitlab-identifier
This refactors Gitlab::Identifier so it uses fewer queries and is
actually tested. Queries are reduced by caching the output as well as
using 1 query (instead of 2) to find a user using an SSH key.
Diffstat (limited to 'app/models/user.rb')
-rw-r--r-- | app/models/user.rb | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 7f5a8562907..508efd85050 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -279,6 +279,11 @@ class User < ActiveRecord::Base find_by('users.username = ? OR users.id = ?', name_or_id.to_s, name_or_id.to_i) end + # Returns a user for the given SSH key. + def find_by_ssh_key_id(key_id) + find_by(id: Key.unscoped.select(:user_id).where(id: key_id)) + end + def build_user(attrs = {}) User.new(attrs) end |