diff options
author | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-02 16:21:49 +0000 |
---|---|---|
committer | Yorick Peterse <yorickpeterse@gmail.com> | 2016-06-02 16:21:49 +0000 |
commit | 61cfda255f42160e2deeb5c37dd7b97b858863e6 (patch) | |
tree | 1da7d5bf166ae3d8b5f46a71e5a47fc8cf33683e | |
parent | f0d6d711174d5d18485dd080d6b7ccd0e1a00604 (diff) | |
parent | 2605a0a844f187daeeff1f16920db445f53e2793 (diff) | |
download | gitlab-ce-61cfda255f42160e2deeb5c37dd7b97b858863e6.tar.gz |
Merge branch 'issue-18032' into 'master'
Cache project build count. Closes #18032
See merge request !4377
-rw-r--r-- | .vagrant_enabled | 0 | ||||
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/models/ci/build.rb | 1 | ||||
-rw-r--r-- | app/models/project.rb | 6 | ||||
-rw-r--r-- | app/views/projects/pipelines/_head.html.haml | 2 | ||||
-rw-r--r-- | features/project/builds/summary.feature | 1 | ||||
-rw-r--r-- | features/steps/project/builds/summary.rb | 4 |
7 files changed, 14 insertions, 1 deletions
diff --git a/.vagrant_enabled b/.vagrant_enabled new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/.vagrant_enabled diff --git a/CHANGELOG b/CHANGELOG index dedaf9090a2..daffb916065 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -28,6 +28,7 @@ v 8.9.0 (unreleased) - Make authentication service for Container Registry to be compatible with < Docker 1.11 - Add Application Setting to configure Container Registry token expire delay (default 5min) - Cache assigned issue and merge request counts in sidebar nav + - Cache project build count in sidebar nav v 8.8.3 - Fix incorrect links on pipeline page when merge request created from fork diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 5e77fda70b9..64723ab6b4b 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -313,6 +313,7 @@ module Ci build_data = Gitlab::BuildDataBuilder.build(self) project.execute_hooks(build_data.dup, :build_hooks) project.execute_services(build_data.dup, :build_hooks) + project.running_or_pending_build_count(force: true) end def artifacts? diff --git a/app/models/project.rb b/app/models/project.rb index 525a82c7534..9ccf6a97df6 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1011,4 +1011,10 @@ class Project < ActiveRecord::Base update_attribute(:pending_delete, true) end + + def running_or_pending_build_count(force: false) + Rails.cache.fetch(['projects', id, 'running_or_pending_build_count'], force: force) do + builds.running_or_pending.count(:all) + end + end end diff --git a/app/views/projects/pipelines/_head.html.haml b/app/views/projects/pipelines/_head.html.haml index 2c8ae625e67..6e757df5417 100644 --- a/app/views/projects/pipelines/_head.html.haml +++ b/app/views/projects/pipelines/_head.html.haml @@ -11,4 +11,4 @@ = link_to project_builds_path(@project), title: 'Builds', class: 'shortcuts-builds' do %span Builds - %span.badge.count.builds_counter= number_with_delimiter(@project.builds.running_or_pending.count(:all)) + %span.badge.count.builds_counter= number_with_delimiter(@project.running_or_pending_build_count) diff --git a/features/project/builds/summary.feature b/features/project/builds/summary.feature index 3c029a973df..550ebccf0d7 100644 --- a/features/project/builds/summary.feature +++ b/features/project/builds/summary.feature @@ -24,3 +24,4 @@ Feature: Project Builds Summary Then recent build has been erased And recent build summary does not have artifacts widget And recent build summary contains information saying that build has been erased + And the build count cache is updated diff --git a/features/steps/project/builds/summary.rb b/features/steps/project/builds/summary.rb index e9e2359146e..374eb0b0e07 100644 --- a/features/steps/project/builds/summary.rb +++ b/features/steps/project/builds/summary.rb @@ -36,4 +36,8 @@ class Spinach::Features::ProjectBuildsSummary < Spinach::FeatureSteps expect(page).to have_content 'Build has been erased' end end + + step 'the build count cache is updated' do + expect(@build.project.running_or_pending_build_count).to eq @build.project.builds.running_or_pending.count(:all) + end end |