Commit 39efd0c0 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Clear cached markdown after renaming projects

parent 389057f0
......@@ -90,6 +90,24 @@ module Gitlab
FileUtils.mv(old_path, new_path)
end
def remove_cached_html_for_projects(project_ids)
update_column_in_batches(:projects, :description_html, nil) do |table, query|
query.where(table[:id].in(project_ids))
end
update_column_in_batches(:issues, :description_html, nil) do |table, query|
query.where(table[:project_id].in(project_ids))
end
update_column_in_batches(:merge_requests, :description_html, nil) do |table, query|
query.where(table[:target_project_id].in(project_ids))
end
update_column_in_batches(:notes, :note_html, nil) do |table, query|
query.where(table[:project_id].in(project_ids))
end
end
def file_storage?
CarrierWave::Uploader::Base.storage == CarrierWave::Storage::File
end
......
......@@ -27,6 +27,7 @@ module Gitlab
move_repositories(namespace, old_full_path, new_full_path)
move_uploads(old_full_path, new_full_path)
move_pages(old_full_path, new_full_path)
remove_cached_html_for_projects(projects_for_namespace(namespace).map(&:id))
end
def move_repositories(namespace, old_full_path, new_full_path)
......@@ -55,8 +56,6 @@ module Gitlab
MigrationClasses::Project.where(namespace_or_children)
end
# This won't scale to huge trees, but it should do for a handful of
# namespaces called `system`.
def child_ids_for_parent(namespace, ids: [])
namespace.children.each do |child|
ids << child.id
......
......@@ -8,6 +8,8 @@ module Gitlab
projects_for_paths.each do |project|
rename_project(project)
end
remove_cached_html_for_projects(projects_for_paths.map(&:id))
end
def rename_project(project)
......@@ -28,10 +30,12 @@ module Gitlab
end
def projects_for_paths
return @projects_for_paths if @projects_for_paths
with_paths = MigrationClasses::Route.arel_table[:path]
.matches_any(path_patterns)
MigrationClasses::Project.joins(:route).where(with_paths)
@projects_for_paths = MigrationClasses::Project.joins(:route).where(with_paths)
end
end
end
......
......@@ -27,6 +27,46 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameBase do
end
end
describe '#remove_cached_html_for_projects' do
let(:project) { create(:empty_project, description_html: 'Project description') }
it 'removes description_html from projects' do
subject.remove_cached_html_for_projects([project.id])
expect(project.reload.description_html).to be_nil
end
it 'removes issue descriptions' do
issue = create(:issue, project: project, description_html: 'Issue description')
subject.remove_cached_html_for_projects([project.id])
expect(issue.reload.description_html).to be_nil
end
it 'removes merge request descriptions' do
merge_request = create(:merge_request,
source_project: project,
target_project: project,
description_html: 'MergeRequest description')
subject.remove_cached_html_for_projects([project.id])
expect(merge_request.reload.description_html).to be_nil
end
it 'removes note html' do
note = create(:note,
project: project,
noteable: create(:issue, project: project),
note_html: 'note description')
subject.remove_cached_html_for_projects([project.id])
expect(note.reload.note_html).to be_nil
end
end
describe '#rename_path_for_routable' do
context 'for namespaces' do
let(:namespace) { create(:namespace, path: 'the-path') }
......
......@@ -139,7 +139,13 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameNamespaces do
subject.rename_namespace(namespace)
end
it 'invalidates the markdown cache of related projects'
it 'invalidates the markdown cache of related projects' do
project = create(:empty_project, namespace: namespace, path: "the-path-project")
expect(subject).to receive(:remove_cached_html_for_projects).with([project.id])
subject.rename_namespace(namespace)
end
end
describe '#rename_namespaces' do
......
......@@ -29,6 +29,23 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameProjects do
end
end
describe '#rename_projects' do
let!(:projects) { create_list(:empty_project, 2, path: 'the-path') }
it 'renames each project' do
expect(subject).to receive(:rename_project).twice
subject.rename_projects
end
it 'invalidates the markdown cache of related projects' do
expect(subject).to receive(:remove_cached_html_for_projects).
with(projects.map(&:id))
subject.rename_projects
end
end
describe '#rename_project' do
let(:project) do
create(:empty_project,
......@@ -68,8 +85,6 @@ describe Gitlab::Database::RenameReservedPathsMigration::RenameProjects do
subject.rename_project(project)
end
it 'invalidates the markdown cache of related projects'
end
describe '#move_repository' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment