Commit 46d1c976 authored by Robert May's avatar Robert May

Fix pipeline status for commit caching

Fixes a bug with the commit cache key used for partial
caching, where the key was changing on every page load.

Changelog: fixed
parent 819b3d12
...@@ -161,7 +161,7 @@ module CommitsHelper ...@@ -161,7 +161,7 @@ module CommitsHelper
ref, ref,
{ {
merge_request: merge_request, merge_request: merge_request,
pipeline_status: hashed_pipeline_status(commit, ref), pipeline_status: commit.status_for(ref),
xhr: request.xhr?, xhr: request.xhr?,
controller: controller.controller_path, controller: controller.controller_path,
path: @path # referred to in #link_to_browse_code path: @path # referred to in #link_to_browse_code
...@@ -242,14 +242,4 @@ module CommitsHelper ...@@ -242,14 +242,4 @@ module CommitsHelper
project_commit_path(project, commit) project_commit_path(project, commit)
end end
end end
private
def hashed_pipeline_status(commit, ref)
status = commit.status_for(ref)
return if status.nil?
Digest::SHA1.hexdigest(status.to_s)
end
end end
...@@ -11,6 +11,8 @@ module Gitlab ...@@ -11,6 +11,8 @@ module Gitlab
attr_reader :subject, :user attr_reader :subject, :user
delegate :cache_key, to: :subject
def initialize(subject, user) def initialize(subject, user)
@subject = subject @subject = subject
@user = user @user = user
......
...@@ -294,7 +294,8 @@ RSpec.describe CommitsHelper do ...@@ -294,7 +294,8 @@ RSpec.describe CommitsHelper do
subject { helper.commit_partial_cache_key(commit, ref: ref, merge_request: merge_request, request: request) } subject { helper.commit_partial_cache_key(commit, ref: ref, merge_request: merge_request, request: request) }
let(:commit) { create(:commit).present(current_user: user) } let(:commit) { create(:commit).present(current_user: user) }
let(:commit_status) { create(:commit_status) } let(:commit_status) { Gitlab::Ci::Status::Running.new(pipeline, user) }
let(:pipeline) { create(:ci_pipeline, :running) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:ref) { "master" } let(:ref) { "master" }
let(:merge_request) { nil } let(:merge_request) { nil }
...@@ -315,7 +316,7 @@ RSpec.describe CommitsHelper do ...@@ -315,7 +316,7 @@ RSpec.describe CommitsHelper do
is_expected.to include( is_expected.to include(
{ {
merge_request: merge_request, merge_request: merge_request,
pipeline_status: Digest::SHA1.hexdigest(commit_status.to_s), pipeline_status: commit_status,
xhr: true, xhr: true,
controller: "commits", controller: "commits",
path: current_path path: current_path
......
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