Commit c8c08546 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre Committed by Ash McKenzie

Remove legacy query to find attachments to sync

This commit removes the legacy queries to find attachments
to sync since we made Foreign Data Wrapper (FDW) a hard
requirement for Geo on GitLab 12.0.
parent 8fe4aaa3
......@@ -44,14 +44,7 @@ module Geo
# @param [Array<Integer>] except_file_ids ids that will be ignored from the query
# rubocop: disable CodeReuse/ActiveRecord
def find_unsynced(batch_size:, except_file_ids: [])
relation =
if use_legacy_queries_for_selective_sync?
legacy_finder.attachments_unsynced(except_file_ids: except_file_ids)
else
attachments_unsynced(except_file_ids: except_file_ids)
end
relation.limit(batch_size)
attachments_unsynced(except_file_ids: except_file_ids).limit(batch_size)
end
# rubocop: enable CodeReuse/ActiveRecord
......
......@@ -16,16 +16,6 @@ module Geo
)
end
def attachments_unsynced(except_file_ids:)
registry_file_ids = Geo::FileRegistry.attachments.pluck_file_key | except_file_ids
legacy_left_outer_join_registry_ids(
syncable,
registry_file_ids,
Upload
)
end
private
def attachments
......
......@@ -503,7 +503,58 @@ describe Geo::AttachmentRegistryFinder, :geo do
stub_fdw_disabled
end
include_examples 'finds all the things'
describe '#find_migrated_local' do
let!(:upload_1) { create(:upload, model: synced_group) }
let!(:upload_2) { create(:upload, model: unsynced_group) }
let!(:upload_3) { create(:upload, :issuable_upload, model: synced_project) }
let!(:upload_4) { create(:upload, model: unsynced_project) }
let!(:upload_5) { create(:upload, model: synced_project) }
let!(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) }
let!(:upload_remote_2) { create(:upload, :object_storage, model: unsynced_project) }
before do
create(:geo_file_registry, :avatar, file_id: upload_remote_1.id)
create(:geo_file_registry, :avatar, file_id: upload_remote_2.id)
end
it 'returns attachments stored remotely and successfully synced locally' do
attachments = subject.find_migrated_local(batch_size: 100, except_file_ids: [upload_remote_2.id])
expect(attachments).to match_ids(upload_remote_1)
end
it 'excludes attachments stored remotely, but not synced yet' do
create(:upload, :object_storage, model: synced_group)
attachments = subject.find_migrated_local(batch_size: 100)
expect(attachments).to match_ids(upload_remote_1, upload_remote_2)
end
context 'with selective sync by namespace' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'returns attachments stored remotely and successfully synced locally' do
attachments = subject.find_migrated_local(batch_size: 10)
expect(attachments).to match_ids(upload_remote_1)
end
end
context 'with selective sync by shard' do
before do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'returns attachments stored remotely and successfully synced locally' do
attachments = subject.find_migrated_local(batch_size: 10)
expect(attachments).to match_ids(upload_remote_2)
end
end
end
describe '#count_syncable' do
let!(:upload_1) { create(:upload, model: synced_group) }
......
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