~cytrogen/masto-fe

ref: d7254bd3327c5ad208b7f74aade749234441b3bc masto-fe/app/lib/vacuum/backups_vacuum.rb -rw-r--r-- 509 bytes
d7254bd3 — Laura Hausmann Update default local-settings 2 years ago
                                                                                
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
# frozen_string_literal: true

class Vacuum::BackupsVacuum
  def initialize(retention_period)
    @retention_period = retention_period
  end

  def perform
    vacuum_expired_backups! if retention_period?
  end

  private

  def vacuum_expired_backups!
    backups_past_retention_period.in_batches.destroy_all
  end

  def backups_past_retention_period
    Backup.unscoped.where(Backup.arel_table[:created_at].lt(@retention_period.ago))
  end

  def retention_period?
    @retention_period.present?
  end
end