Class: ActiveRecord::Materialized::SummaryDeltaBuilder

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

Overview

The SummaryDelta a single write contributes. Subtracting the “before” snapshot and adding the “after” uniformly handles inserts, deletes, in-place updates, and group-key changes (a move between partitions).

Instance Method Summary collapse

Constructor Details

#initialize(change, analysis, group_columns) ⇒ SummaryDeltaBuilder

Returns a new instance of SummaryDeltaBuilder.



13
14
15
16
17
# File 'lib/activerecord/materialized/summary_delta_builder.rb', line 13

def initialize(change, analysis, group_columns)
  @change = change
  @analysis = analysis
  @group_columns = group_columns
end

Instance Method Details

#buildObject



20
21
22
23
24
25
# File 'lib/activerecord/materialized/summary_delta_builder.rb', line 20

def build
  delta = SummaryDelta.new
  apply!(delta, @change.before, -1) unless @change.before.empty?
  apply!(delta, @change.after, 1) unless @change.after.empty?
  delta.prune!
end