Skip to content

Orphan Cleanup Service #28

@dmitrytrager

Description

@dmitrytrager

Remove entities no longer in manifest

  class OrphanCleanup
    def cleanup(manifest)
      external_file_ids = manifest.dig_all("providers", "topics", "files", "id")
      external_topic_ids = manifest.dig_all("providers", "topics", "id")
      external_provider_ids = manifest["providers"].pluck("id")
      external_tag_ids = manifest["tags"].pluck("id")

      # ActiveStorage will purge attached blobs automatically
      TopicFile.where.not(external_id: external_file_ids).destroy_all
      Topic.where.not(external_id: external_topic_ids).destroy_all
      ContentProvider.where.not(external_id: external_provider_ids).destroy_all
      Tag.where.not(external_id: external_tag_ids).destroy_all
    end
  end

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions