Class: ActiveRecord::Materialized::MaintenanceDelta Private

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/activerecord/materialized/maintenance_delta.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.

Pending scoped-recompute maintenance: the affected partition keys, or a full-partition marker.

Constant Summary collapse

SCOPED =

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

T.let(:scoped, Symbol)
FULL =

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

T.let(:full_partition, Symbol)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope:, key_tuples: []) ⇒ MaintenanceDelta

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



22
23
24
25
# File 'lib/activerecord/materialized/maintenance_delta.rb', line 22

def initialize(scope:, key_tuples: [])
  @scope = scope
  @key_tuples = key_tuples
end

Instance Attribute Details

#key_tuplesObject (readonly)

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.



19
20
21
# File 'lib/activerecord/materialized/maintenance_delta.rb', line 19

def key_tuples
  @key_tuples
end

#scopeObject (readonly)

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.



16
17
18
# File 'lib/activerecord/materialized/maintenance_delta.rb', line 16

def scope
  @scope
end

Class Method Details

.deserialize(payload) ⇒ 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.



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/activerecord/materialized/maintenance_delta.rb', line 67

def self.deserialize(payload)
  return nil if payload.blank?

  scope_name = payload["scope"]&.to_sym
  return nil if scope_name.nil?

  if scope_name == FULL
    full_partition
  else
    tuples = T.cast(payload["key_tuples"], T.nilable(T::Array[T::Array[String]])) || []
    scoped(tuples)
  end
end

.full_partitionObject

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.



33
34
35
# File 'lib/activerecord/materialized/maintenance_delta.rb', line 33

def self.full_partition
  new(scope: FULL)
end

.scoped(key_tuples) ⇒ 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.



28
29
30
# File 'lib/activerecord/materialized/maintenance_delta.rb', line 28

def self.scoped(key_tuples)
  new(scope: SCOPED, key_tuples: key_tuples)
end

Instance Method Details

#full_partition?Boolean

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:

  • (Boolean)


38
39
40
# File 'lib/activerecord/materialized/maintenance_delta.rb', line 38

def full_partition?
  scope == FULL
end

#merge(other) ⇒ 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.



50
51
52
53
54
55
56
# File 'lib/activerecord/materialized/maintenance_delta.rb', line 50

def merge(other)
  return other if other.full_partition?
  return self if full_partition?

  combined = (key_tuples + other.key_tuples).uniq
  self.class.scoped(combined)
end

#serializeObject

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.



59
60
61
62
63
64
# File 'lib/activerecord/materialized/maintenance_delta.rb', line 59

def serialize
  {
    "scope" => scope.to_s,
    "key_tuples" => key_tuples
  }
end

#tracked_partition_countObject

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.



45
46
47
# File 'lib/activerecord/materialized/maintenance_delta.rb', line 45

def tracked_partition_count
  full_partition? ? 0 : key_tuples.size
end