From 6dff1a9a2b1d4fb006f75bb941d9b68e4a01ba11 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Fri, 22 Apr 2016 00:39:31 -0700 Subject: [PATCH] Fix Error 500 due to stale cache when projects are renamed or transferred Closes gitlab-org/gitlab-ee#506 --- CHANGELOG | 1 + app/models/project.rb | 6 ++---- app/services/projects/transfer_service.rb | 2 ++ spec/models/project_spec.rb | 7 ++----- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2d1c561fb82..fbc3ee194cb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -8,6 +8,7 @@ v 8.7.1 (unreleased) - Fix license detection to detect all license files, not only known licenses. !3878 - Use the `can?` helper instead of `current_user.can?`. !3882 - Prevent users from deleting Webhooks via API they do not own + - Fix Error 500 due to stale cache when projects are renamed or transferred v 8.7.0 - Gitlab::GitAccess and Gitlab::GitAccessWiki are now instrumented diff --git a/app/models/project.rb b/app/models/project.rb index 7aa21b19e67..0420c6a61ae 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -820,13 +820,11 @@ class Project < ActiveRecord::Base wiki = Repository.new("#{old_path}.wiki", self) if repo.exists? - repo.expire_cache - repo.expire_emptiness_caches + repo.before_delete end if wiki.exists? - wiki.expire_cache - wiki.expire_emptiness_caches + wiki.before_delete end end diff --git a/app/services/projects/transfer_service.rb b/app/services/projects/transfer_service.rb index 79a27f4af7e..111b3ec05ea 100644 --- a/app/services/projects/transfer_service.rb +++ b/app/services/projects/transfer_service.rb @@ -34,6 +34,8 @@ module Projects raise TransferError.new("Project with same path in target namespace already exists") end + project.expire_caches_before_rename(old_path) + # Apply new namespace id and visibility level project.namespace = new_namespace project.visibility_level = new_namespace.visibility_level unless project.visibility_level_allowed_by_group? diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index becc743de31..e33c7d62ff4 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -719,11 +719,8 @@ describe Project, models: true do with('foo.wiki', project). and_return(wiki) - expect(repo).to receive(:expire_cache) - expect(repo).to receive(:expire_emptiness_caches) - - expect(wiki).to receive(:expire_cache) - expect(wiki).to receive(:expire_emptiness_caches) + expect(repo).to receive(:before_delete) + expect(wiki).to receive(:before_delete) project.expire_caches_before_rename('foo') end