Class: ActiveRecord::Materialized::MaintenanceDeltaBuilder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord/materialized/maintenance_delta_builder.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.

Derives the affected partition keys for a write from its ActiveRecord change payload.

Instance Method Summary collapse

Constructor Details

#initialize(change, key_columns, resolver: nil) ⇒ MaintenanceDeltaBuilder

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.

Returns a new instance of MaintenanceDeltaBuilder.



9
10
11
12
13
# File 'lib/activerecord/materialized/maintenance_delta_builder.rb', line 9

def initialize(change, key_columns, resolver: nil)
  @change = change
  @key_columns = key_columns
  @resolver = resolver
end

Instance Method Details

#buildObject

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.



15
16
17
18
19
20
21
22
23
24
# File 'lib/activerecord/materialized/maintenance_delta_builder.rb', line 15

def build
  return MaintenanceDelta.full_partition if @key_columns.empty?

  # A resolver is an explicit per-table mapping, so it is authoritative for
  # that table's writes (it maps to the group key wherever it lives, even if
  # the written row happens to carry a same-named column); otherwise the key
  # comes from the written row's own payload.
  tuples = @resolver ? resolved_tuples : extract_tuples
  tuples.empty? ? MaintenanceDelta.full_partition : MaintenanceDelta.scoped(tuples.uniq)
end