Commit 662f8af4 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'fix-cache-key-expiration-for-commits' into 'master'

Fix bug where transferring a project would result in stale commit links

Transferring a project to another namespace updates the project's updated_at
field, but since the cache key did not depend on the object, the page fragments
were not invalidated. This resulted in stale links to the commits. Changing
the cache key to use the project pathname solves this issue.

Closes gitlab-org/omnibus-gitlab#843

See merge request !1497
parents 2b493695 3fbcc511
Please view this file on the master branch, on stable branches it's out of date. Please view this file on the master branch, on stable branches it's out of date.
v 8.1.0 (unreleased) v 8.1.0 (unreleased)
- Fix bug where transferring a project would result in stale commit links (Stan Hu)
- Include full path of source and target branch names in New Merge Request page (Stan Hu) - Include full path of source and target branch names in New Merge Request page (Stan Hu)
- Fix Message-ID header to be RFC 2111-compliant to prevent e-mails being dropped (Stan Hu) - Fix Message-ID header to be RFC 2111-compliant to prevent e-mails being dropped (Stan Hu)
- Add user preference to view activities as default dashboard (Stan Hu) - Add user preference to view activities as default dashboard (Stan Hu)
......
...@@ -296,7 +296,7 @@ module ProjectsHelper ...@@ -296,7 +296,7 @@ module ProjectsHelper
def readme_cache_key def readme_cache_key
sha = @project.commit.try(:sha) || 'nil' sha = @project.commit.try(:sha) || 'nil'
[@project.id, sha, "readme"].join('-') [@project.path_with_namespace, sha, "readme"].join('-')
end end
def round_commit_count(project) def round_commit_count(project)
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
- note_count = notes.user.count - note_count = notes.user.count
- ci_commit = project.ci_commit(commit.sha) - ci_commit = project.ci_commit(commit.sha)
- cache_key = [project.id, commit.id, note_count] - cache_key = [project.path_with_namespace, commit.id, note_count]
- cache_key.push(ci_commit.status) if ci_commit - cache_key.push(ci_commit.status) if ci_commit
= cache(cache_key) do = cache(cache_key) do
......
...@@ -61,13 +61,13 @@ describe ProjectsHelper do ...@@ -61,13 +61,13 @@ describe ProjectsHelper do
end end
it "returns a valid cach key" do it "returns a valid cach key" do
expect(helper.send(:readme_cache_key)).to eq("#{project.id}-#{project.commit.id}-readme") expect(helper.send(:readme_cache_key)).to eq("#{project.path_with_namespace}-#{project.commit.id}-readme")
end end
it "returns a valid cache key if HEAD does not exist" do it "returns a valid cache key if HEAD does not exist" do
allow(project).to receive(:commit) { nil } allow(project).to receive(:commit) { nil }
expect(helper.send(:readme_cache_key)).to eq("#{project.id}-nil-readme") expect(helper.send(:readme_cache_key)).to eq("#{project.path_with_namespace}-nil-readme")
end end
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