Class: ActiveRecord::Materialized::RefreshScheduler Private

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

Dispatches a view’s configured refresh strategy (‘:async` / `:immediate` / `:manual`) after a write.

Class Method Summary collapse

Class Method Details

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



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/activerecord/materialized/refresh_scheduler.rb', line 14

def schedule(view_class)
  # Capture the transition before marking dirty so the async dispatcher
  # can coalesce: a bulk write only needs one job for the whole burst.
  newly_dirty = !view_class.dirty?
  view_class.mark_dependencies_changed!

  case view_class.resolved_refresh_strategy
  when :manual
    nil
  when :immediate
    view_class.refresh!
  when :async
    dispatch_async(view_class, newly_dirty)
  else
    raise ArgumentError, "Unknown refresh strategy: #{view_class.resolved_refresh_strategy}"
  end
end