Class: ActiveRecord::Materialized::DependencyRegistry Private

Inherits:
Object
  • Object
show all
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

.install_callbacks_for(view_class) ⇒ 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.

(Re)installs the built-in callback tracker for a view's already-declared dependency tables. Invoked by change_source :callbacks so opting in works whether it precedes or follows depends_on.



52
53
54
# File 'lib/activerecord/materialized/dependency_registry.rb', line 52

def install_callbacks_for(view_class)
  view_class.dependency_tables.each { |table| subscribe_source_table!(table, view_class) }
end

.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.

Coarse ingestion signal: something changed in these tables but the caller cannot describe the individual write. Enqueues a full recompute (the only correct scope without a partition key) and schedules it — idempotent, so safe to call repeatedly and after callback-skipping bulk loads.



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

def mark_dirty_for_tables!(tables)
  affected_views(tables).each do |view|
    MaintenanceStore.new(view).merge!(MaintenanceDelta.full_partition)
    RefreshScheduler.schedule(view)
  end
end

.publish_write_change!(change, source: nil) ⇒ 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.

Records a committed write and schedules refresh for the affected views. source identifies the publisher so no view is maintained by two sources: a callback publish (:callbacks) drives only callback-backed views, and an explicit ingestion-API publish (nil) drives only externally-fed views.



29
30
31
32
33
34
35
36
# File 'lib/activerecord/materialized/dependency_registry.rb', line 29

def publish_write_change!(change, source: nil)
  affected_views([change.table_name]).each do |view|
    next unless delivers_to?(view, source)

    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.



10
11
12
13
14
15
16
17
18
19
# File 'lib/activerecord/materialized/dependency_registry.rb', line 10

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

  normalized.each do |table|
    bucket = dependency_index[table]
    bucket << view_class unless bucket.include?(view_class)
    subscribe_source_table!(table, view_class)
  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.



56
57
58
59
# File 'lib/activerecord/materialized/dependency_registry.rb', line 56

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.



21
22
23
# File 'lib/activerecord/materialized/dependency_registry.rb', line 21

def views_for_table(table)
  dependency_index[normalize_table(table)]
end