Sha256: a8dd342eed6beb40e1aafb150fd770e5f5b2f0457faad51eb7f8212849a066a9
Contents?: true
Size: 951 Bytes
Versions: 33
Compression:
Stored size: 951 Bytes
Contents
# frozen_string_literal: true module Katalyst module Content module GarbageCollection extend ActiveSupport::Concern included do after_update :remove_stale_versions end def remove_stale_versions transaction do # find all the versions that are not linked to the record orphaned_versions = versions.inactive next unless orphaned_versions.any? # find items that are not included in active versions orphaned_items = items.pluck(:id) - versions.active.pluck(:nodes).flat_map { |k| k.map(&:id) }.uniq # delete orphaned items with a 2 hour grace period to allow for in-progress editing items.where(id: orphaned_items, updated_at: ..2.hours.ago).destroy_all # delete orphaned versions without a grace period as they can only be created by updates orphaned_versions.destroy_all end end end end end
Version data entries
33 entries across 33 versions & 1 rubygems