summaryrefslogtreecommitdiff
path: root/app/workers/remove_unreferenced_lfs_objects_worker.rb
blob: c67ab6e356ad5788a7885103fa2f6db7444062a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

class RemoveUnreferencedLfsObjectsWorker
  include ApplicationWorker

  data_consistency :always

  # rubocop:disable Scalability/CronWorkerContext
  # This worker does not perform work scoped to a context
  include CronjobQueue
  # rubocop:enable Scalability/CronWorkerContext

  feature_category :git_lfs
  deduplicate :until_executed
  idempotent!

  def perform
    number_of_removed_files = 0

    LfsObject.unreferenced_in_batches do |lfs_objects_without_projects|
      number_of_removed_files += lfs_objects_without_projects.destroy_all.count # rubocop: disable Cop/DestroyAll
    end

    number_of_removed_files
  end
end