From 516a405eb277e088d3b4ae3cb6e64f0bd2d3aff0 Mon Sep 17 00:00:00 2001 From: Bob Van Landuyt Date: Thu, 6 Apr 2017 14:20:29 +0200 Subject: Take the ref of a pipeline into account when caching status --- lib/gitlab/cache/ci/project_pipeline_status.rb | 27 +++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'lib/gitlab/cache') diff --git a/lib/gitlab/cache/ci/project_pipeline_status.rb b/lib/gitlab/cache/ci/project_pipeline_status.rb index 882b4da1725..b358f2efa4f 100644 --- a/lib/gitlab/cache/ci/project_pipeline_status.rb +++ b/lib/gitlab/cache/ci/project_pipeline_status.rb @@ -5,7 +5,7 @@ module Gitlab module Cache module Ci class ProjectPipelineStatus - attr_accessor :sha, :status, :project, :loaded + attr_accessor :sha, :status, :ref, :project, :loaded delegate :commit, to: :project @@ -16,12 +16,16 @@ module Gitlab end def self.update_for_pipeline(pipeline) - new(pipeline.project, sha: pipeline.sha, status: pipeline.status).store_in_cache_if_needed + new(pipeline.project, + sha: pipeline.sha, + status: pipeline.status, + ref: pipeline.ref).store_in_cache_if_needed end - def initialize(project, sha: nil, status: nil) + def initialize(project, sha: nil, status: nil, ref: nil) @project = project @sha = sha + @ref = ref @status = status end @@ -35,37 +39,42 @@ module Gitlab if has_cache? load_from_cache else - load_from_commit + load_from_project store_in_cache end self.loaded = true end - def load_from_commit + def load_from_project return unless commit self.sha = commit.sha self.status = commit.status + self.ref = project.default_branch end # We only cache the status for the HEAD commit of a project # This status is rendered in project lists def store_in_cache_if_needed - return unless sha return delete_from_cache unless commit - store_in_cache if commit.sha == self.sha + return unless sha + return unless ref + + if commit.sha == sha && project.default_branch == ref + store_in_cache + end end def load_from_cache Gitlab::Redis.with do |redis| - self.sha, self.status = redis.hmget(cache_key, :sha, :status) + self.sha, self.status, self.ref = redis.hmget(cache_key, :sha, :status, :ref) end end def store_in_cache Gitlab::Redis.with do |redis| - redis.mapped_hmset(cache_key, { sha: sha, status: status }) + redis.mapped_hmset(cache_key, { sha: sha, status: status, ref: ref }) end end -- cgit v1.2.3