Class: ActiveRecord::Materialized::ReadRouter Private

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

Routes a read to the cache table or to the cold-read fallback (populate-on-read for keyed reads), emitting the read instrumentation event for whichever path it serves.

Instance Method Summary collapse

Constructor Details

#initialize(view_class) ⇒ ReadRouter

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



11
12
13
# File 'lib/activerecord/materialized/read_router.rb', line 11

def initialize(view_class)
  @view_class = view_class
end

Instance Method Details

#partition_scope(args) ⇒ 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.

Per-partition fast path for keyed reads: serve fresh partitions from the cache, otherwise read through and enqueue maintenance (populate-on-read).



22
23
24
25
26
27
28
29
30
31
# File 'lib/activerecord/materialized/read_router.rb', line 22

def partition_scope(args)
  return cache if @view_class.materialized?

  keys = PartitionState.keys_from(@view_class, args)
  return cold if keys.nil?
  return cache if PartitionState.new(@view_class).all_fresh?(keys)

  enqueue_partition_maintenance(keys)
  cold
end

#scopeObject

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.

Routing for reads with no partition predicate to exploit.



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

def scope
  @view_class.materialized? ? cache : cold
end