summaryrefslogtreecommitdiff
path: root/app/models/project.rb
diff options
context:
space:
mode:
authorYorick Peterse <yorickpeterse@gmail.com>2016-02-25 17:43:47 +0100
committerYorick Peterse <yorickpeterse@gmail.com>2016-02-26 12:36:52 +0100
commit1dfef90a878ea675fb5f3460a659a0d33d7fd9e7 (patch)
tree1d082e1c1dd14dc26c8ccd7b1692bfecff6fba1f /app/models/project.rb
parentbb3563b5cd063772fa16c934404e7912d9f3d726 (diff)
downloadgitlab-ce-renaming-repository-caching.tar.gz
Flush repository caches before renaming projectsrenaming-repository-caching
This ensures that if a project is later re-created using the old path it doesn't end up re-using the old cache. This also ensures we don't keep the cache around until its expired by Redis itself. Fixes gitlab-org/gitlab-ce#13790
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 95ad88c76ae..13679cbd9b7 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -711,6 +711,8 @@ class Project < ActiveRecord::Base
old_path_with_namespace = File.join(namespace_dir, path_was)
new_path_with_namespace = File.join(namespace_dir, path)
+ expire_caches_before_rename(old_path_with_namespace)
+
if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace)
# If repository moved successfully we need to send update instructions to users.
# However we cannot allow rollback since we moved repository
@@ -739,6 +741,22 @@ class Project < ActiveRecord::Base
Gitlab::UploadsTransfer.new.rename_project(path_was, path, namespace.path)
end
+ # Expires various caches before a project is renamed.
+ def expire_caches_before_rename(old_path)
+ repo = Repository.new(old_path, self)
+ wiki = Repository.new("#{old_path}.wiki", self)
+
+ if repo.exists?
+ repo.expire_cache
+ repo.expire_emptiness_caches
+ end
+
+ if wiki.exists?
+ wiki.expire_cache
+ wiki.expire_emptiness_caches
+ end
+ end
+
def hook_attrs
{
name: name,