summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Frye <joshfng@gmail.com>2016-06-01 10:50:32 -0400
committerJosh Frye <joshfng@gmail.com>2016-06-02 09:11:57 -0400
commitd92cae5ee01b3daeea2d7d927a9de143954d4d89 (patch)
treee858220669e5d2b2d0cc32e87e8d25de0b8b29b0
parenta74973c910353118a4a5119fe94a09418dc34316 (diff)
downloadgitlab-ce-issue-18032.tar.gz
Refactor. Add tests.issue-18032
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/ci/build.rb2
-rw-r--r--app/models/project.rb8
-rw-r--r--app/views/layouts/nav/_project.html.haml9
-rw-r--r--app/views/projects/pipelines/_head.html.haml2
-rw-r--r--features/project/builds/summary.feature1
-rw-r--r--features/steps/project/builds/summary.rb4
7 files changed, 10 insertions, 17 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 848aaa8506e..34652d2dcfb 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -25,6 +25,7 @@ v 8.9.0 (unreleased)
- Measure queue duration between gitlab-workhorse and Rails
- 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 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 f597f920a3b..64723ab6b4b 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -313,7 +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.expire_running_or_pending_build_count
+ project.running_or_pending_build_count(force: true)
end
def artifacts?
diff --git a/app/models/project.rb b/app/models/project.rb
index c105c61286e..4ffc60d0efe 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1008,13 +1008,9 @@ class Project < ActiveRecord::Base
update_attribute(:pending_delete, true)
end
- def running_or_pending_build_count
- Rails.cache.fetch(['projects', id, 'running_or_pending_build_count']) do
+ 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
-
- def expire_running_or_pending_build_count
- Rails.cache.delete(['projects', id, 'running_or_pending_build_count'])
- end
end
diff --git a/app/views/layouts/nav/_project.html.haml b/app/views/layouts/nav/_project.html.haml
index 86d2ba9ba26..2c9b9006668 100644
--- a/app/views/layouts/nav/_project.html.haml
+++ b/app/views/layouts/nav/_project.html.haml
@@ -52,15 +52,6 @@
= icon('ship fw')
%span
Pipelines
- %span.badge.count.ci_counter= number_with_delimiter(@project.ci_commits.running_or_pending.count)
-
- - if project_nav_tab? :builds
- = nav_link(controller: %w(builds)) do
- = link_to project_builds_path(@project), title: 'Builds', class: 'shortcuts-builds' do
- = icon('cubes fw')
- %span
- Builds
- %span.badge.count.builds_counter= number_with_delimiter(@project.running_or_pending_build_count)
- if project_nav_tab? :container_registry
= nav_link(controller: %w(container_registry)) do
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