Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2019-08-01 19:18:17 +0300
committerStan Hu <stanhu@gmail.com>2019-08-05 16:42:34 +0300
commitd3a3db4218e10c65c2e87c763ad02169f3736883 (patch)
tree4fc682cc529520bef4e69d740c9fdea99d46c2c3 /app/models/deploy_key.rb
parentded3b7574dbd6e1b3249c9e5bbcc61090c733142 (diff)
Speed up loading and filtering deploy keys and their projects
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.
Diffstat (limited to 'app/models/deploy_key.rb')
-rw-r--r--app/models/deploy_key.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/app/models/deploy_key.rb b/app/models/deploy_key.rb
index fb50da39ca3..0bd90bd28e3 100644
--- a/app/models/deploy_key.rb
+++ b/app/models/deploy_key.rb
@@ -9,6 +9,7 @@ class DeployKey < Key
scope :in_projects, ->(projects) { joins(:deploy_keys_projects).where('deploy_keys_projects.project_id in (?)', projects) }
scope :are_public, -> { where(public: true) }
+ scope :with_projects, -> { includes(deploy_keys_projects: { project: [:route, :namespace] }) }
ignore_column :can_push
@@ -23,7 +24,7 @@ class DeployKey < Key
end
def almost_orphaned?
- self.deploy_keys_projects.length == 1
+ self.deploy_keys_projects.count == 1
end
def destroyed_when_orphaned?
@@ -47,6 +48,6 @@ class DeployKey < Key
end
def projects_with_write_access
- Project.preload(:route).where(id: deploy_keys_projects.with_write_access.select(:project_id))
+ Project.with_route.where(id: deploy_keys_projects.with_write_access.select(:project_id))
end
end