Stop using pluck to get deploy keys for a user

This commit is contained in:
Nick Thomas 2019-08-01 16:22:56 +01:00 committed by Stan Hu
parent 0c0232e623
commit ded3b7574d
2 changed files with 6 additions and 6 deletions

View File

@ -2,6 +2,7 @@
class DeployKey < Key
include IgnorableColumn
include FromUnion
has_many :deploy_keys_projects, inverse_of: :deploy_key, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
has_many :projects, through: :deploy_keys_projects

View File

@ -933,7 +933,7 @@ class User < ApplicationRecord
end
def project_deploy_keys
DeployKey.unscoped.in_projects(authorized_projects.pluck(:id)).distinct(:id)
DeployKey.in_projects(authorized_projects.select(:id)).distinct(:id)
end
def highest_role
@ -941,11 +941,10 @@ class User < ApplicationRecord
end
def accessible_deploy_keys
@accessible_deploy_keys ||= begin
key_ids = project_deploy_keys.pluck(:deploy_key_id)
key_ids.push(*DeployKey.are_public.pluck(:id))
DeployKey.where(id: key_ids)
end
DeployKey.from_union([
DeployKey.where(id: project_deploy_keys.select(:deploy_key_id)),
DeployKey.are_public
])
end
def created_by