class

Task::CollectGarbage

Inherits Task::Singleton < Task < Ktistec::Model::Polymorphic < Ktistec::Model::Common < Ktistec::Model < Reference < Object

Garbage collection task for ActivityPub objects.

Garbage collection identifies and removes objects that are not connected to the user through preservation rules, described below.

How It Works

  1. Identification: Identifies objects that should be preserved based on preservation rules, described below.

  2. Deletion: Deletes objects and all associated records (tags, activities, relationships, translations).

  3. Optimization: Runs SQLite VACUUM and OPTIMIZE to reclaim freed space.

Preservation Rules

Objects are preserved if they meet any of the following criteria:

  • Objects attributed to local users or to remote actors that local users follow

  • Objects associated with activities created by local users or by remote actors that local users follow

  • Objects with hashtags, mentions, or that are part of threads that local users follow

  • Objects in relationships with local users (timelines,

  • notifications, the outbox)

  • Objects in a thread (unless every object in the thread can be

  • deleted)

  • Recent objects

Of Note

  • Deleting an object will remove many associated records (activities, relationships, tags, translations), but never other objects.

  • Either entire threads are preserved or they are eligible for deletion.

Constants

DEFAULT_MAX_AGE_DAYS = 365
DEFAULT_MAX_DELETE_COUNT = 1000
Log = ::Log.for(self)

Constructors

current_instance

Returns the current active instance of this singleton task.

Creates and saves a new instance if no active instance exists.

Source

Class methods

ensure_scheduled

Ensures the singleton task is scheduled.

Typically called on server startup to ensure singleton tasks are created and scheduled.

Source
find_active

Finds the active instance.

Returns nil if no active instance exists.

Source
followed_hashtags
Source
followed_mentions
Source
followed_or_following_actors
Source
followed_threads
Source
get_max_age_days
Source
get_max_age_days=(get_max_age_days : Int32)
Source
get_max_delete_count
Source
get_max_delete_count=(get_max_delete_count : Int32)
Source
objects_associated_with_followed_actor_activities
Source
objects_associated_with_followed_content
Source
objects_associated_with_user_activities
Source
objects_attributed_to_followed_actors
Source
objects_attributed_to_user
Source
objects_in_threads

Finds all objects that are part of the same thread as any preserved object.

Uses the "thread" column when available; falls back to the "in_reply_to_iri" column for legacy threads.

Source
objects_in_user_relationships
Source
objects_to_preserve
Source
objects_too_recent_to_delete
Source

Instance methods

delete_object_and_associations(object_iri : String)

Deletes an object and associated records.

This method deletes the object and all records (except other objects via the in_reply_to association) that reference that object.

Returns the number of objects deleted.

Parameters

  • object_iri - The IRI of the object to delete
Source
perform(max_age_days = self.class.get_max_age_days, max_delete_count = self.class.get_max_delete_count)

Performs garbage collection when scheduled.

Source
perform_on_demand(max_age_days = self.class.get_max_age_days, max_delete_count = Int32::MAX)

Performs garbage collection on-demand.

Source