Remove upload registry query builder

Part of our effort to treat registry tables
as the SSOT for uploads.
parent 50dbb5ad
......@@ -25,11 +25,10 @@ module Geo
def execute
return unless Gitlab::Geo.secondary?
uploads = Geo::Fdw::Upload.for_model(project)
uploads = Upload.for_model(project)
log_info("Expiring replicated attachments after project rename", count: uploads.count)
schedule_file_removal(uploads)
mark_for_resync!
end
# Project's base directory for attachments storage
......@@ -51,18 +50,14 @@ module Geo
log_info("Scheduled to remove file", file_path: file_path)
end
Geo::UploadRegistry.where(file_id: upload.id).delete_all
end
Geo::FileRemovalWorker.bulk_perform_async(paths_to_remove) # rubocop:disable Scalability/BulkPerformWithContext
end
# rubocop: enable CodeReuse/ActiveRecord
def mark_for_resync!
Gitlab::Geo::Fdw::UploadRegistryQueryBuilder.new
.for_model(project)
.delete_all
end
# This is called by LogHelpers to build json log with context info
#
# @see ::Gitlab::Geo::LogHelpers
......
# frozen_string_literal: true
# Builder class to create composable queries using FDW to
# retrieve file registries.
#
# Basic usage:
#
# Gitlab::Geo::Fdw::UploadRegistryQueryBuilder.new.for_model(project)
#
module Gitlab
module Geo
class Fdw
class UploadRegistryQueryBuilder < BaseQueryBuilder
# rubocop:disable CodeReuse/ActiveRecord
def for_model(model)
reflect(
query
.joins(fdw_inner_join_uploads)
.where(
fdw_table[:model_id].eq(model.id)
.and(fdw_table[:model_type].eq(model.class.name))
)
)
end
# rubocop:enable CodeReuse/ActiveRecord
private
def base
::Geo::UploadRegistry.select(registry_table[Arel.star])
end
def registry_table
::Geo::UploadRegistry.arel_table
end
def fdw_table
::Geo::Fdw::Upload.arel_table
end
def fdw_inner_join_uploads
registry_table
.join(fdw_table, Arel::Nodes::InnerJoin)
.on(registry_table[:file_id].eq(fdw_table[:id]))
.join_sources
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Gitlab::Geo::Fdw::UploadRegistryQueryBuilder, :geo, :geo_fdw do
let(:project) { create(:project) }
let(:upload_1) { create(:upload, :issuable_upload, model: project) }
let(:upload_2) { create(:upload, :issuable_upload, model: project) }
let(:upload_3) { create(:upload, :issuable_upload) }
let!(:registry_1) { create(:geo_upload_registry, file_id: upload_1.id) }
let!(:registry_2) { create(:geo_upload_registry, :attachment, file_id: upload_2.id) }
let!(:registry_3) { create(:geo_upload_registry, file_id: upload_3.id) }
describe '#for_model' do
it 'returns registries for uploads that belong to the model' do
expect(subject.for_model(project)).to match_ids(registry_1, registry_2)
end
end
end
......@@ -2,7 +2,7 @@
require 'spec_helper'
RSpec.describe Geo::FilesExpireService, :geo, :geo_fdw do
RSpec.describe Geo::FilesExpireService, :geo do
let(:project) { create(:project, :legacy_storage) }
let!(:old_full_path) { project.full_path }
......@@ -43,7 +43,6 @@ RSpec.describe Geo::FilesExpireService, :geo, :geo_fdw do
context 'when not in Geo secondary node' do
it 'no-op execute action' do
expect(subject).not_to receive(:schedule_file_removal)
expect(subject).not_to receive(:mark_for_resync!)
subject.execute
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