class
   Task::CollectGarbage
 
  - Task::CollectGarbage
 - Task
 - Reference
 - Object
 
Overview
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
- 
Identification: Identifies objects that should be preserved based on preservation rules, described below.
 - 
Deletion: Deletes objects and all associated records (tags, activities, relationships, translations).
 - 
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.
 
Included Modules
Defined in:
models/task/collect_garbage.crConstant Summary
- 
        DEFAULT_MAX_AGE_DAYS = 
365 - 
        DEFAULT_MAX_DELETE_COUNT = 
1000 - 
        Log = 
::Log.for(self) 
Constructors
- 
        .current_instance : self
        
          
Returns the current active instance of this singleton task.
 
Class Method Summary
- 
        .ensure_scheduled
        
          
Ensures the singleton task is scheduled.
 - 
        .find_active : self | Nil
        
          
Finds the active instance.
 - .followed_hashtags
 - .followed_mentions
 - .followed_or_following_actors
 - .followed_threads
 - .get_max_age_days : Int32
 - .get_max_age_days=(get_max_age_days : Int32)
 - .get_max_delete_count : Int32
 - .get_max_delete_count=(get_max_delete_count : Int32)
 - .objects_associated_with_followed_actor_activities
 - .objects_associated_with_followed_content
 - .objects_associated_with_user_activities
 - .objects_attributed_to_followed_actors
 - .objects_attributed_to_user
 - 
        .objects_in_threads
        
          
Finds all objects that are part of the same thread as any preserved object.
 - .objects_in_user_relationships
 - .objects_to_preserve
 - .objects_too_recent_to_delete
 
Instance Method Summary
- 
        #delete_object_and_associations(object_iri : String)
        
          
Deletes an object and associated records.
 - 
        #perform(max_age_days = self.class.get_max_age_days, max_delete_count = self.class.get_max_delete_count)
        
          
Performs garbage collection when scheduled.
 - 
        #perform_on_demand(max_age_days = self.class.get_max_age_days, max_delete_count = Int32::MAX)
        
          
Performs garbage collection on-demand.
 
Instance methods inherited from class Task
  
  
    
      backtrace : Array(String) | Nil
    backtrace, 
    
  
    
      backtrace=(backtrace : Array(String) | Nil)
    backtrace=, 
    
  
    
      complete : Bool
    complete, 
    
  
    
      complete=(complete : Bool)
    complete=, 
    
  
    
      gone?
    gone?, 
    
  
    
      last_attempt_at : Time | Nil
    last_attempt_at, 
    
  
    
      last_attempt_at=(last_attempt_at : Time | Nil)
    last_attempt_at=, 
    
  
    
      next_attempt_at : Time | Nil
    next_attempt_at, 
    
  
    
      next_attempt_at=(next_attempt_at : Time | Nil)
    next_attempt_at=, 
    
  
    
      past_due?(now = Time.utc)
    past_due?, 
    
  
    
      perform
    perform, 
    
  
    
      runnable?
    runnable?, 
    
  
    
      running : Bool
    running, 
    
  
    
      running=(running : Bool)
    running=, 
    
  
    
      schedule(next_attempt_at = nil)
    schedule, 
    
  
    
      source_iri : String
    source_iri, 
    
  
    
      source_iri=(source_iri : String)
    source_iri=, 
    
  
    
      subject_iri : String
    subject_iri, 
    
  
    
      subject_iri=(subject_iri : String)
    subject_iri=
    
  
      
      
  Class methods inherited from class Task
  
  
    
      all_subtypes
    all_subtypes, 
    
  
    
      clean_up_running_tasks
    clean_up_running_tasks, 
    
  
    
      destroy_old_tasks
    destroy_old_tasks, 
    
  
    
      priority
    priority, 
    
  
    
      priority=(priority : Int32)
    priority=, 
    
  
    
      scheduled(now = Time.utc, reserve = false)
    scheduled
    
  
      
    
      
  Instance methods inherited from module Ktistec::Model::Polymorphic
  
  
    
      _validate_type
    _validate_type, 
    
  
    
      as_a(as _as : T.class) : T forall T
    as_a, 
    
  
    
      type : String
    type, 
    
  
    
      type=(type : String)
    type=
    
  
      
      
      
  Macros inherited from module Ktistec::Model::Polymorphic
  
  
    
      find(_id id, *, as _as)find(*, as _as, **options) find
Instance methods inherited from module Ktistec::Model::Common
  
  
    
      created_at : Time
    created_at, 
    
  
    
      created_at=(created_at : Time)
    created_at=, 
    
  
    
      updated_at : Time
    updated_at, 
    
  
    
      updated_at=(updated_at : Time)
    updated_at=
    
  
      
      
      
    
      
  Instance methods inherited from module Ktistec::Model
  
  
    
      ==(other : self)==(other) ==, _run_validations _run_validations, _save_model(skip_validation = false) _save_model, _serialize_graph(nodes, association = nil, index = nil, skip_associated = false) _serialize_graph, assign(properties : Hash(String, Any), *, _strict : Bool = false) forall Any
assign(*, _strict : Bool = false, **properties) assign, changed!(*properties : Symbol) changed!, changed?
changed?(*properties : Symbol) changed?, clear_changed!
clear_changed!(*properties : Symbol) clear_changed!, destroy destroy, destroyed? destroyed?, errors errors, hash(hasher) hash, id : Int64 | Nil id, id=(id : Int64 | Nil) id=, inspect(io : IO) inspect, new_record? new_record?, reload! reload!, save(skip_validation = false, skip_associated = false) save, serialize_graph(skip_associated = false) serialize_graph, table_name table_name, to_h to_h, to_json(json : JSON::Builder) to_json, to_s(io : IO) to_s, update_property(property, value) update_property, valid?(skip_associated = false) valid?, validate(skip_associated = false) validate
Constructor methods inherited from module Ktistec::Model
  
  
    
      new(properties : Hash(String, Any), *, _strict : Bool = false) forall Anynew(*, _strict : Bool = false, **properties) new
Macros inherited from module Ktistec::Model
  
  
    
      belongs_to(name, primary_key = id, foreign_key = nil, class_name = nil, inverse_of = nil)
    belongs_to, 
    
  
    
      derived(decl, *, aliased_to)
    derived, 
    
  
    
      has_many(name, primary_key = id, foreign_key = nil, class_name = nil, inverse_of = nil)
    has_many, 
    
  
    
      has_one(name, primary_key = id, foreign_key = nil, class_name = nil, inverse_of = nil)
    has_one, 
    
  
    
      validates(property, &block)
    validates
    
  
    
      
      
      
      
    
      
      
      
      
    
  Constructor Detail
Returns the current active instance of this singleton task.
Creates and saves a new instance if no active instance exists.
Class Method Detail
Ensures the singleton task is scheduled.
Typically called on server startup to ensure singleton tasks are created and scheduled.
Finds the active instance.
Returns nil if no active instance exists.
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.
Instance Method Detail
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
Performs garbage collection when scheduled.
Performs garbage collection on-demand.