Geo - Remove duplicated code to remove tracking database entries

parent 10fa290b
......@@ -22,9 +22,11 @@ module EE
end
def log_geo_event(project)
::Geo::RepositoryDeletedEventStore.new(project,
::Geo::RepositoryDeletedEventStore.new(
project,
repo_path: repo_path,
wiki_path: wiki_path).create
wiki_path: wiki_path
).create
end
# Removes physical repository in a Geo replicated secondary node
......@@ -37,16 +39,9 @@ module EE
flush_caches(project)
trash_repositories!
remove_tracking_entries!
log_info("Project \"#{project.name}\" was removed")
end
def remove_tracking_entries!
return unless ::Gitlab::Geo.secondary?
::Geo::ProjectRegistry.where(project_id: project.id).delete_all
end
private
def log_audit_event(project)
......
......@@ -122,7 +122,6 @@ module Gitlab
def handle_repository_deleted(event_log)
event = event_log.repository_deleted_event
disk_path = File.join(event.repository_storage_path, event.deleted_path)
job_id = ::Geo::RepositoryDestroyService
......
......@@ -139,11 +139,11 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
context 'when replaying a repository deleted event' do
let(:event_log) { create(:geo_event_log, :deleted_event) }
let(:project) { event_log.repository_deleted_event.project }
let!(:event_log_state) { create(:geo_event_log_state, event_id: event_log.id - 1) }
let(:repository_deleted_event) { event_log.repository_deleted_event }
let(:project) { repository_deleted_event.project }
it 'does not create a new project registry' do
it 'does not create a tracking database entry' do
expect { daemon.run_once! }.not_to change(Geo::ProjectRegistry, :count)
end
......@@ -158,6 +158,12 @@ describe Gitlab::Geo::LogCursor::Daemon, :postgresql, :clean_gitlab_redis_shared
daemon.run_once!
end
it 'removes the tracking database entry if exist' do
create(:geo_project_registry, :synced, project: project)
expect { daemon.run_once! }.to change(Geo::ProjectRegistry, :count).by(-1)
end
end
context 'when replaying a repositories changed event' 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