Class: ActiveRecord::Materialized::DependencyRegistry Private

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/activerecord/materialized/dependency_registry.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Maps dependency tables to the views that depend on them and publishes committed writes to them.

Class Method Summary collapse

Class Method Details

.mark_dirty_for_tables!(tables) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



49
50
51
# File 'lib/activerecord/materialized/dependency_registry.rb', line 49

def mark_dirty_for_tables!(tables)
  affected_views(tables).each(&:mark_dependencies_changed!)
end

.publish_write_change!(change) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



41
42
43
44
45
46
# File 'lib/activerecord/materialized/dependency_registry.rb', line 41

def publish_write_change!(change)
  affected_views([change.table_name]).each do |view|
    view.record_write_change!(change)
    RefreshScheduler.schedule(view)
  end
end

.register(view_class, tables) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



24
25
26
27
28
29
30
31
32
33
# File 'lib/activerecord/materialized/dependency_registry.rb', line 24

def register(view_class, tables)
  normalized = Array(tables).flat_map { |entry| normalize_dependency(entry) }
  T.unsafe(view_class).instance_variable_set(:@dependency_tables, normalized)

  normalized.each do |table|
    bucket = T.cast(dependency_index[table], T::Array[ViewClass])
    bucket << view_class unless bucket.include?(view_class)
    subscribe_source_table!(table)
  end
end

.reset!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



54
55
56
57
# File 'lib/activerecord/materialized/dependency_registry.rb', line 54

def reset!
  @dependency_index = Hash.new { |hash, key| hash[key] = [] }
  ActiveRecord::Materialized::DependencyTrackable.reset!
end

.views_for_table(table) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



36
37
38
# File 'lib/activerecord/materialized/dependency_registry.rb', line 36

def views_for_table(table)
  T.must(dependency_index[normalize_table(table)])
end