summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosh Frye <joshfng@gmail.com>2016-05-31 16:01:16 -0400
committerJosh Frye <joshfng@gmail.com>2016-06-01 15:03:53 -0400
commita74973c910353118a4a5119fe94a09418dc34316 (patch)
tree1c23612b9f3ee50bd4b66e849f539444a7ad7507
parent15157e1f08ae1e15628cd682c39697cd1be4e834 (diff)
downloadgitlab-ce-a74973c910353118a4a5119fe94a09418dc34316.tar.gz
Invalidate cache on build change
-rw-r--r--app/models/ci/build.rb1
-rw-r--r--app/models/project.rb6
2 files changed, 6 insertions, 1 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 5e77fda70b9..f597f920a3b 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.expire_running_or_pending_build_count
end
def artifacts?
diff --git a/app/models/project.rb b/app/models/project.rb
index 42982b1e1e9..c105c61286e 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1009,8 +1009,12 @@ class Project < ActiveRecord::Base
end
def running_or_pending_build_count
- Rails.cache.fetch(['projects', id, 'running_or_pending_build_count'], expires_in: 60) do
+ Rails.cache.fetch(['projects', id, 'running_or_pending_build_count']) 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