Flush repository cache before import project data

GitHub Pull Requests importer handle with the repository while
importing data, we need to make sure that the cached values are valid.
parent a55fc416
...@@ -364,6 +364,11 @@ class Repository ...@@ -364,6 +364,11 @@ class Repository
expire_tag_count_cache expire_tag_count_cache
end end
def before_import
expire_emptiness_caches
expire_exists_cache
end
# Runs code after a repository has been forked/imported. # Runs code after a repository has been forked/imported.
def after_import def after_import
expire_emptiness_caches expire_emptiness_caches
......
...@@ -46,6 +46,8 @@ module Projects ...@@ -46,6 +46,8 @@ module Projects
def import_data def import_data
return unless has_importer? return unless has_importer?
project.repository.before_import
unless importer.execute unless importer.execute
raise Error, 'The remote data could not be imported.' raise Error, 'The remote data could not be imported.'
end end
......
...@@ -612,6 +612,20 @@ describe Repository, models: true do ...@@ -612,6 +612,20 @@ describe Repository, models: true do
end end
end end
describe '#before_import' do
it 'flushes the emptiness cachess' do
expect(repository).to receive(:expire_emptiness_caches)
repository.before_import
end
it 'flushes the exists cache' do
expect(repository).to receive(:expire_exists_cache)
repository.before_import
end
end
describe '#after_import' do describe '#after_import' do
it 'flushes the emptiness cachess' do it 'flushes the emptiness cachess' do
expect(repository).to receive(:expire_emptiness_caches) expect(repository).to receive(:expire_emptiness_caches)
......
...@@ -72,6 +72,23 @@ describe Projects::ImportService, services: true do ...@@ -72,6 +72,23 @@ describe Projects::ImportService, services: true do
expect(result[:status]).to eq :success expect(result[:status]).to eq :success
end end
it 'flushes various caches' do
expect_any_instance_of(Gitlab::Shell).to receive(:import_repository).
with(project.path_with_namespace, project.import_url).
and_return(true)
expect_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).
and_return(true)
expect_any_instance_of(Repository).to receive(:expire_emptiness_caches).
and_call_original
expect_any_instance_of(Repository).to receive(:expire_exists_cache).
and_call_original
subject.execute
end
it 'fails if importer fails' do it 'fails if importer fails' do
expect_any_instance_of(Gitlab::Shell).to receive(:import_repository).with(project.path_with_namespace, project.import_url).and_return(true) expect_any_instance_of(Gitlab::Shell).to receive(:import_repository).with(project.path_with_namespace, project.import_url).and_return(true)
expect_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).and_return(false) expect_any_instance_of(Gitlab::GithubImport::Importer).to receive(:execute).and_return(false)
......
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