d3a3db4218
This commit changes how we eager-load projects, routes, and namespaces required by the deploy keys endpoint, getting a 10x improvement in my local testing. The endpoint still doesn't scale in-general, but going from ~13 seconds to dump a 63K result to generating the same thing in ~1.6 seconds seems like a good improvement to me.
25 lines
713 B
Ruby
25 lines
713 B
Ruby
# frozen_string_literal: true
|
|
|
|
class DeployKeyEntity < Grape::Entity
|
|
expose :id
|
|
expose :user_id
|
|
expose :title
|
|
expose :fingerprint
|
|
expose :destroyed_when_orphaned?, as: :destroyed_when_orphaned
|
|
expose :almost_orphaned?, as: :almost_orphaned
|
|
expose :created_at
|
|
expose :updated_at
|
|
expose :deploy_keys_projects, using: DeployKeysProjectEntity do |deploy_key|
|
|
deploy_key.deploy_keys_projects.select do |deploy_key_project|
|
|
!deploy_key_project.project&.pending_delete? &&
|
|
Ability.allowed?(options[:user], :read_project, deploy_key_project.project)
|
|
end
|
|
end
|
|
expose :can_edit
|
|
|
|
private
|
|
|
|
def can_edit
|
|
Ability.allowed?(options[:user], :update_deploy_key, object)
|
|
end
|
|
end
|