diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-03-10 15:32:31 +0100 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-03-10 15:32:31 +0100 |
commit | f2992cf343c28736efa5b49fc6a4c3e40a9f0a8f (patch) | |
tree | 2d3e620982d8f8dc1d23845c244af3e40ed12a81 /app | |
parent | 491ac7ce4b79c901e23799d2062f9f013f08c6c3 (diff) | |
download | gitlab-ce-f2992cf343c28736efa5b49fc6a4c3e40a9f0a8f.tar.gz |
Optimize Project#ci_service(s)optimize-project-ci-services
The method Project#ci_services would load all services into memory
(including _all_ their columns) and then use Enumerable#select to reduce
the list. Project#ci_service in turn would further reduce this list down
to just 1 Service instance.
Instead of doing all this in Ruby we can just offload the work to the
database, reducing the amount of time spent in these methods. These
changes reduce the time of the first call to Project#ci_services from
around 240 ms to around 10 ms, though the final timings will vary based
on database load. Because Project#ci_service is memoized there's no
further overhead introduced by using a database query.
Fixes gitlab-org/gitlab-ce#14186
Diffstat (limited to 'app')
-rw-r--r-- | app/models/project.rb | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 426464dee81..65829bec77a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -528,11 +528,11 @@ class Project < ActiveRecord::Base end def ci_services - services.select { |service| service.category == :ci } + services.where(category: :ci) end def ci_service - @ci_service ||= ci_services.find(&:activated?) + @ci_service ||= ci_services.reorder(nil).find_by(active: true) end def jira_tracker? |