summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-02-16 23:11:56 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2016-02-17 11:38:18 +0100
commitb1203108b0eda20f87c75004f035e9e7a51f1124 (patch)
tree3c5664f0eba5aa0626e8896be4917327d7973980 /app
parenta9e0301c230a81242d476f30d7089565919214b3 (diff)
downloadgitlab-ce-b1203108b0eda20f87c75004f035e9e7a51f1124.tar.gz
Flush all repository caches when deleting a repoexpire-fork-import-caches
This ensures that _all_ caches (including any caches normally only flushed under certain conditions) are flushed whenever a project is removed. Because cache keys are based on project namespaces (excluding IDs) not doing so could result in a newly created project re-using old caches (if the project was re-created using the same name).
Diffstat (limited to 'app')
-rw-r--r--app/models/repository.rb9
-rw-r--r--app/services/projects/destroy_service.rb14
2 files changed, 22 insertions, 1 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 5696504e7ec..1c33a7f9679 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -238,6 +238,15 @@ class Repository
expire_branch_cache(branch_name)
end
+ # Expires _all_ caches, including those that would normally only be expired
+ # under specific conditions.
+ def expire_all_caches!
+ expire_cache
+ expire_root_ref_cache
+ expire_emptiness_caches
+ expire_has_visible_content_cache
+ end
+
def expire_branch_cache(branch_name = nil)
# When we push to the root branch we have to flush the cache for all other
# branches as their statistics are based on the commits relative to the
diff --git a/app/services/projects/destroy_service.rb b/app/services/projects/destroy_service.rb
index 294157b4f0e..f4dcb142850 100644
--- a/app/services/projects/destroy_service.rb
+++ b/app/services/projects/destroy_service.rb
@@ -16,11 +16,15 @@ module Projects
return false unless can?(current_user, :remove_project, project)
project.team.truncate
- project.repository.expire_cache unless project.empty_repo?
repo_path = project.path_with_namespace
wiki_path = repo_path + '.wiki'
+ # Flush the cache for both repositories. This has to be done _before_
+ # removing the physical repositories as some expiration code depends on
+ # Git data (e.g. a list of branch names).
+ flush_caches(project, wiki_path)
+
Project.transaction do
project.destroy!
@@ -70,5 +74,13 @@ module Projects
def removal_path(path)
"#{path}+#{project.id}#{DELETED_FLAG}"
end
+
+ def flush_caches(project, wiki_path)
+ project.repository.expire_all_caches! if project.repository.exists?
+
+ wiki_repo = Repository.new(wiki_path, project)
+
+ wiki_repo.expire_all_caches! if wiki_repo.exists?
+ end
end
end