diff options
Diffstat (limited to 'lib/gitlab/cleanup')
-rw-r--r-- | lib/gitlab/cleanup/orphan_job_artifact_files.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/cleanup/orphan_job_artifact_files_batch.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/cleanup/orphan_lfs_file_references.rb | 32 | ||||
-rw-r--r-- | lib/gitlab/cleanup/project_upload_file_finder.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/cleanup/project_uploads.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/cleanup/remote_uploads.rb | 2 |
6 files changed, 19 insertions, 23 deletions
diff --git a/lib/gitlab/cleanup/orphan_job_artifact_files.rb b/lib/gitlab/cleanup/orphan_job_artifact_files.rb index 017adc7be4a..6d18f9070cc 100644 --- a/lib/gitlab/cleanup/orphan_job_artifact_files.rb +++ b/lib/gitlab/cleanup/orphan_job_artifact_files.rb @@ -18,7 +18,7 @@ module Gitlab @limit = limit @dry_run = dry_run @niceness = (niceness || DEFAULT_NICENESS).downcase - @logger = logger || Rails.logger # rubocop:disable Gitlab/RailsLogger + @logger = logger || Gitlab::AppLogger @total_found = @total_cleaned = 0 new_batch! diff --git a/lib/gitlab/cleanup/orphan_job_artifact_files_batch.rb b/lib/gitlab/cleanup/orphan_job_artifact_files_batch.rb index 6ad05c7b2e4..4b1d16eb974 100644 --- a/lib/gitlab/cleanup/orphan_job_artifact_files_batch.rb +++ b/lib/gitlab/cleanup/orphan_job_artifact_files_batch.rb @@ -22,7 +22,7 @@ module Gitlab attr_reader :batch_size, :dry_run attr_accessor :artifact_files - def initialize(batch_size:, dry_run: true, logger: Rails.logger) # rubocop:disable Gitlab/RailsLogger + def initialize(batch_size:, dry_run: true, logger: Gitlab::AppLogger) @batch_size = batch_size @dry_run = dry_run @logger = logger diff --git a/lib/gitlab/cleanup/orphan_lfs_file_references.rb b/lib/gitlab/cleanup/orphan_lfs_file_references.rb index 3df243e319e..14eac474e27 100644 --- a/lib/gitlab/cleanup/orphan_lfs_file_references.rb +++ b/lib/gitlab/cleanup/orphan_lfs_file_references.rb @@ -12,7 +12,7 @@ module Gitlab def initialize(project, dry_run: true, logger: nil, limit: nil) @project = project @dry_run = dry_run - @logger = logger || Rails.logger # rubocop:disable Gitlab/RailsLogger + @logger = logger || Gitlab::AppLogger @limit = limit end @@ -25,7 +25,7 @@ module Gitlab private def remove_orphan_references - invalid_references = project.lfs_objects_projects.where(lfs_object: orphan_objects) # rubocop:disable CodeReuse/ActiveRecord + invalid_references = project.lfs_objects_projects.lfs_object_in(orphan_objects) if dry_run log_info("Found invalid references: #{invalid_references.count}") @@ -41,26 +41,22 @@ module Gitlab end end - def lfs_oids_from_repository - project.repository.gitaly_blob_client.get_all_lfs_pointers.map(&:lfs_oid) - end - - def orphan_oids - lfs_oids_from_database - lfs_oids_from_repository - end + def orphan_objects + # Get these first so racing with a git push can't remove any LFS objects + oids = project.lfs_objects_oids - def lfs_oids_from_database - oids = [] + repos = [ + project.repository, + project.design_repository, + project.wiki.repository + ].select(&:exists?) - project.lfs_objects.each_batch do |relation| - oids += relation.pluck(:oid) # rubocop:disable CodeReuse/ActiveRecord + repos.flat_map do |repo| + oids -= repo.gitaly_blob_client.get_all_lfs_pointers.map(&:lfs_oid) end - oids - end - - def orphan_objects - LfsObject.where(oid: orphan_oids) # rubocop:disable CodeReuse/ActiveRecord + # The remaining OIDs are not used by any repository, so are orphans + LfsObject.for_oids(oids) end def log_info(msg) diff --git a/lib/gitlab/cleanup/project_upload_file_finder.rb b/lib/gitlab/cleanup/project_upload_file_finder.rb index 3d35d474f5d..0f40f683354 100644 --- a/lib/gitlab/cleanup/project_upload_file_finder.rb +++ b/lib/gitlab/cleanup/project_upload_file_finder.rb @@ -49,7 +49,7 @@ module Gitlab cmd = %W[#{ionice} -c Idle] + cmd if ionice log_msg = "find command: \"#{cmd.join(' ')}\"" - Rails.logger.info log_msg # rubocop:disable Gitlab/RailsLogger + Gitlab::AppLogger.info log_msg cmd end diff --git a/lib/gitlab/cleanup/project_uploads.rb b/lib/gitlab/cleanup/project_uploads.rb index 056e075cb21..77231665e7e 100644 --- a/lib/gitlab/cleanup/project_uploads.rb +++ b/lib/gitlab/cleanup/project_uploads.rb @@ -8,7 +8,7 @@ module Gitlab attr_reader :logger def initialize(logger: nil) - @logger = logger || Rails.logger # rubocop:disable Gitlab/RailsLogger + @logger = logger || Gitlab::AppLogger end def run!(dry_run: true) diff --git a/lib/gitlab/cleanup/remote_uploads.rb b/lib/gitlab/cleanup/remote_uploads.rb index 42c93b7aecb..6cadb9424f7 100644 --- a/lib/gitlab/cleanup/remote_uploads.rb +++ b/lib/gitlab/cleanup/remote_uploads.rb @@ -7,7 +7,7 @@ module Gitlab BATCH_SIZE = 100 def initialize(logger: nil) - @logger = logger || Rails.logger # rubocop:disable Gitlab/RailsLogger + @logger = logger || Gitlab::AppLogger end def run!(dry_run: false) |