Commit 421957cf authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'sh-expire-content-cache-after-import' into 'master'

Expire Wiki content cache after importing a repository

Closes #47546

See merge request gitlab-org/gitlab-ce!19617
parents 87eb2b6e 1756eea5
...@@ -1616,6 +1616,7 @@ class Project < ActiveRecord::Base ...@@ -1616,6 +1616,7 @@ class Project < ActiveRecord::Base
def after_import def after_import
repository.after_import repository.after_import
wiki.repository.after_import
import_finish import_finish
remove_import_jid remove_import_jid
update_project_counter_caches update_project_counter_caches
......
---
title: Expire Wiki content cache after importing a repository
merge_request:
author:
type: fixed
...@@ -42,8 +42,6 @@ module Gitlab ...@@ -42,8 +42,6 @@ module Gitlab
klass.new(project, client, parallel: false).execute klass.new(project, client, parallel: false).execute
end end
project.repository.after_import
true true
end end
end end
......
...@@ -50,7 +50,7 @@ class GithubImport ...@@ -50,7 +50,7 @@ class GithubImport
end end
if import_success if import_success
@project.import_finish @project.after_import
puts "Import finished. Timings: #{timings}".color(:green) puts "Import finished. Timings: #{timings}".color(:green)
else else
puts "Import was not successful. Errors were as follows:" puts "Import was not successful. Errors were as follows:"
......
...@@ -30,7 +30,6 @@ describe Gitlab::GithubImport::SequentialImporter do ...@@ -30,7 +30,6 @@ describe Gitlab::GithubImport::SequentialImporter do
expect(instance).to receive(:execute) expect(instance).to receive(:execute)
end end
expect(repository).to receive(:after_import)
expect(importer.execute).to eq(true) expect(importer.execute).to eq(true)
end end
end end
......
...@@ -1733,7 +1733,11 @@ describe Project do ...@@ -1733,7 +1733,11 @@ describe Project do
.with(project.repository_storage, project.disk_path, project.import_url) .with(project.repository_storage, project.disk_path, project.import_url)
.and_return(true) .and_return(true)
expect_any_instance_of(Repository).to receive(:after_import) # Works around https://github.com/rspec/rspec-mocks/issues/910
expect(described_class).to receive(:find).with(project.id).twice.and_return(project)
expect(project.repository).to receive(:after_import)
.and_call_original
expect(project.wiki.repository).to receive(:after_import)
.and_call_original .and_call_original
end end
...@@ -3398,10 +3402,11 @@ describe Project do ...@@ -3398,10 +3402,11 @@ describe Project do
end end
describe '#after_import' do describe '#after_import' do
let(:project) { build(:project) } let(:project) { create(:project) }
it 'runs the correct hooks' do it 'runs the correct hooks' do
expect(project.repository).to receive(:after_import) expect(project.repository).to receive(:after_import)
expect(project.wiki.repository).to receive(:after_import)
expect(project).to receive(:import_finish) expect(project).to receive(:import_finish)
expect(project).to receive(:update_project_counter_caches) expect(project).to receive(:update_project_counter_caches)
expect(project).to receive(:remove_import_jid) expect(project).to receive(:remove_import_jid)
......
...@@ -55,10 +55,15 @@ describe RepositoryForkWorker do ...@@ -55,10 +55,15 @@ describe RepositoryForkWorker do
it 'flushes various caches' do it 'flushes various caches' do
expect_fork_repository.and_return(true) expect_fork_repository.and_return(true)
expect_any_instance_of(Repository).to receive(:expire_emptiness_caches) # Works around https://github.com/rspec/rspec-mocks/issues/910
expect(Project).to receive(:find).with(fork_project.id).and_return(fork_project)
expect(fork_project.repository).to receive(:expire_emptiness_caches)
.and_call_original .and_call_original
expect(fork_project.repository).to receive(:expire_exists_cache)
expect_any_instance_of(Repository).to receive(:expire_exists_cache) .and_call_original
expect(fork_project.wiki.repository).to receive(:expire_emptiness_caches)
.and_call_original
expect(fork_project.wiki.repository).to receive(:expire_exists_cache)
.and_call_original .and_call_original
perform! perform!
......
...@@ -22,8 +22,11 @@ describe RepositoryImportWorker do ...@@ -22,8 +22,11 @@ describe RepositoryImportWorker do
expect_any_instance_of(Projects::ImportService).to receive(:execute) expect_any_instance_of(Projects::ImportService).to receive(:execute)
.and_return({ status: :ok }) .and_return({ status: :ok })
expect_any_instance_of(Repository).to receive(:expire_emptiness_caches) # Works around https://github.com/rspec/rspec-mocks/issues/910
expect_any_instance_of(Project).to receive(:import_finish) expect(Project).to receive(:find).with(project.id).and_return(project)
expect(project.repository).to receive(:expire_emptiness_caches)
expect(project.wiki.repository).to receive(:expire_emptiness_caches)
expect(project).to receive(:import_finish)
subject.perform(project.id) subject.perform(project.id)
end end
...@@ -34,9 +37,11 @@ describe RepositoryImportWorker do ...@@ -34,9 +37,11 @@ describe RepositoryImportWorker do
expect_any_instance_of(Projects::ImportService).to receive(:execute) expect_any_instance_of(Projects::ImportService).to receive(:execute)
.and_return({ status: :ok }) .and_return({ status: :ok })
expect_any_instance_of(Project).to receive(:after_import).and_call_original # Works around https://github.com/rspec/rspec-mocks/issues/910
expect_any_instance_of(Repository).to receive(:expire_emptiness_caches) expect(Project).to receive(:find).with(project.id).and_return(project)
expect_any_instance_of(Project).to receive(:import_finish) expect(project.repository).to receive(:expire_emptiness_caches)
expect(project.wiki.repository).to receive(:expire_emptiness_caches)
expect(project).to receive(:import_finish)
subject.perform(project.id) subject.perform(project.id)
end end
......
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