Class: SourceMonitor::Items::RetentionStrategies::SoftDelete

Inherits:
Object
  • Object
show all
Defined in:
lib/source_monitor/items/retention_strategies/soft_delete.rb

Instance Method Summary collapse

Constructor Details

#initialize(source:) ⇒ SoftDelete

Returns a new instance of SoftDelete.



7
8
9
# File 'lib/source_monitor/items/retention_strategies/soft_delete.rb', line 7

def initialize(source:)
  @source = source
end

Instance Method Details

#apply(batch:, now: Time.current) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/source_monitor/items/retention_strategies/soft_delete.rb', line 11

def apply(batch:, now: Time.current)
  ids = Array(batch.pluck(:id))
  return 0 if ids.empty?

  timestamp = normalized_timestamp(now)

  # Use with_deleted to update items that may already be marked as deleted
  SourceMonitor::Item.with_deleted.where(id: ids).update_all(
    deleted_at: timestamp,
    updated_at: timestamp
  )

  adjust_source_counter(ids.length)
  ids.length
end