Skip to content

Commit

Permalink
Merge branch 'fix-cache-key-expiration-for-commits' into 'master'
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dzaporozhets committed Oct 3, 2015
2 parents 2b49369 + 3fbcc51 commit 662f8af
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/projects_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def last_push_event

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)
Expand Down
2 changes: 1 addition & 1 deletion app/views/projects/commits/_commit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/helpers/projects_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@
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

0 comments on commit 662f8af

Please sign in to comment.