Commit dd2e91cc authored by Matija Čupić's avatar Matija Čupić

Cache pipeline status only for specific sha

parent 982276c3
...@@ -41,8 +41,8 @@ module Gitlab ...@@ -41,8 +41,8 @@ module Gitlab
end end
end end
def self.cache_key_for_project(project) def self.cache_key_for_project(project, cache_sha = project.commit&.sha)
"#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:projects/#{project.id}/pipeline_status" "#{Gitlab::Redis::Cache::CACHE_NAMESPACE}:projects/#{project.id}/pipeline_status/#{cache_sha}"
end end
def self.update_for_pipeline(pipeline) def self.update_for_pipeline(pipeline)
...@@ -84,9 +84,7 @@ module Gitlab ...@@ -84,9 +84,7 @@ module Gitlab
def load_from_project def load_from_project
return unless commit return unless commit
self.sha = commit.sha self.sha, self.status, self.ref = commit.sha, commit.status, project.default_branch
self.status = commit.status
self.ref = project.default_branch
end end
# We only cache the status for the HEAD commit of a project # We only cache the status for the HEAD commit of a project
...@@ -104,6 +102,8 @@ module Gitlab ...@@ -104,6 +102,8 @@ module Gitlab
def load_from_cache def load_from_cache
Gitlab::Redis::Cache.with do |redis| Gitlab::Redis::Cache.with do |redis|
self.sha, self.status, self.ref = redis.hmget(cache_key, :sha, :status, :ref) self.sha, self.status, self.ref = redis.hmget(cache_key, :sha, :status, :ref)
self.status = nil if self.status.empty?
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment