diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-10-03 08:45:27 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-10-03 08:45:27 +0000 |
commit | 662f8af497656754c7ad27c0250d2aae825b8545 (patch) | |
tree | b64531cc34d03041f1ce7760c859f262e179d691 | |
parent | 2b493695a39cd4e30e92cf7830e33f2f126cb30a (diff) | |
parent | 3fbcc51102ad12948efe7d0fd1d69c1150aba416 (diff) | |
download | gitlab-ce-662f8af497656754c7ad27c0250d2aae825b8545.tar.gz |
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
-rw-r--r-- | CHANGELOG | 1 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 2 | ||||
-rw-r--r-- | app/views/projects/commits/_commit.html.haml | 2 | ||||
-rw-r--r-- | spec/helpers/projects_helper_spec.rb | 4 |
4 files changed, 5 insertions, 4 deletions
diff --git a/CHANGELOG b/CHANGELOG index f01da3fe7dd..ec23d0f1172 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,7 @@ Please view this file on the master branch, on stable branches it's out of date. 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) - 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) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 7b4747ce3d7..a0220af4c30 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -296,7 +296,7 @@ module ProjectsHelper def readme_cache_key sha = @project.commit.try(:sha) || 'nil' - [@project.id, sha, "readme"].join('-') + [@project.path_with_namespace, sha, "readme"].join('-') end def round_commit_count(project) diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index efad4cb1473..cddd5aa3a83 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -5,7 +5,7 @@ - note_count = notes.user.count - 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(cache_key) do diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index 99abb95d906..53e56ebff44 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -61,13 +61,13 @@ describe ProjectsHelper do end 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 it "returns a valid cache key if HEAD does not exist" do 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 |