Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/lfs_object.rb')
-rw-r--r--app/models/lfs_object.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/app/models/lfs_object.rb b/app/models/lfs_object.rb
index b837b902e2d..53e7d52c558 100644
--- a/app/models/lfs_object.rb
+++ b/app/models/lfs_object.rb
@@ -7,7 +7,7 @@ class LfsObject < ApplicationRecord
include ObjectStorage::BackgroundMove
include FileStoreMounter
- has_many :lfs_objects_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
+ has_many :lfs_objects_projects
has_many :projects, -> { distinct }, through: :lfs_objects_projects
scope :with_files_stored_locally, -> { where(file_store: LfsObjectUploader::Store::LOCAL) }
@@ -18,6 +18,8 @@ class LfsObject < ApplicationRecord
mount_file_store_uploader LfsObjectUploader
+ BATCH_SIZE = 3000
+
def self.not_linked_to_project(project)
where('NOT EXISTS (?)',
project.lfs_objects_projects.select(1).where('lfs_objects_projects.lfs_object_id = lfs_objects.id'))
@@ -37,13 +39,14 @@ class LfsObject < ApplicationRecord
file_store == LfsObjectUploader::Store::LOCAL
end
- # rubocop: disable Cop/DestroyAll
- def self.destroy_unreferenced
- joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id")
- .where(lfs_objects_projects: { id: nil })
- .destroy_all
+ def self.unreferenced_in_batches
+ each_batch(of: BATCH_SIZE, order: :desc) do |lfs_objects|
+ relation = lfs_objects.where('NOT EXISTS (?)',
+ LfsObjectsProject.select(1).where('lfs_objects_projects.lfs_object_id = lfs_objects.id'))
+
+ yield relation if relation.any?
+ end
end
- # rubocop: enable Cop/DestroyAll
def self.calculate_oid(path)
self.hexdigest(path)