Class: ActiveRecord::Materialized::Metadata Private
- Inherits:
-
Object
- Object
- ActiveRecord::Materialized::Metadata
- Extended by:
- T::Sig
- Defined in:
- lib/activerecord/materialized/metadata.rb,
lib/activerecord/materialized/metadata/schema.rb,
lib/activerecord/materialized/metadata/timestamps.rb,
lib/activerecord/materialized/metadata/maintenance_payload.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.
Reads and writes a view’s freshness metadata row (dirty, warm, last_refreshed_at, …).
Defined Under Namespace
Modules: MaintenancePayload, Schema, Timestamps
Instance Attribute Summary collapse
- #view_class ⇒ Object readonly private
Instance Method Summary collapse
- #clear_maintenance_payload! ⇒ Object private
- #dirty? ⇒ Boolean private
- #ensure_schema! ⇒ Object private
-
#initialize(view_class) ⇒ Metadata
constructor
private
A new instance of Metadata.
- #last_refreshed_at ⇒ Object private
- #maintenance_payload ⇒ Object private
- #mark_dirty! ⇒ Object private
- #mark_failed!(error) ⇒ Object private
- #mark_refreshed!(row_count:, duration_ms:) ⇒ Object private
- #mark_refreshing! ⇒ Object private
- #mark_warm! ⇒ Object private
- #record ⇒ Object private
- #record_maintenance_payload!(payload) ⇒ Object private
- #refresh_duration_ms ⇒ Object private
- #refreshing? ⇒ Boolean private
- #row_count ⇒ Object private
- #stale?(max_staleness: view_class.resolved_max_staleness) ⇒ Boolean private
- #warm? ⇒ Boolean private
Constructor Details
#initialize(view_class) ⇒ Metadata
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 Metadata.
20 21 22 23 |
# File 'lib/activerecord/materialized/metadata.rb', line 20 def initialize(view_class) @view_class = view_class @schema_ensured = T.let(false, T::Boolean) end |
Instance Attribute Details
#view_class ⇒ Object (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.
17 18 19 |
# File 'lib/activerecord/materialized/metadata.rb', line 17 def view_class @view_class end |
Instance Method Details
#clear_maintenance_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.
104 105 106 |
# File 'lib/activerecord/materialized/metadata.rb', line 104 def clear_maintenance_payload! MaintenancePayload.clear!(self) end |
#dirty? ⇒ 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.
63 64 65 |
# File 'lib/activerecord/materialized/metadata.rb', line 63 def dirty? !!record.dirty? end |
#ensure_schema! ⇒ 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.
35 36 37 38 39 40 |
# File 'lib/activerecord/materialized/metadata.rb', line 35 def ensure_schema! return if @schema_ensured Schema.ensure_table!(view_class) @schema_ensured = true end |
#last_refreshed_at ⇒ 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.
43 44 45 |
# File 'lib/activerecord/materialized/metadata.rb', line 43 def last_refreshed_at record.last_refreshed_at end |
#maintenance_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.
99 100 101 |
# File 'lib/activerecord/materialized/metadata.rb', line 99 def maintenance_payload MaintenancePayload.fetch(self) end |
#mark_dirty! ⇒ 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.
89 90 91 |
# File 'lib/activerecord/materialized/metadata.rb', line 89 def mark_dirty! record.update!(dirty: true) end |
#mark_failed!(error) ⇒ 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.
130 131 132 133 134 135 |
# File 'lib/activerecord/materialized/metadata.rb', line 130 def mark_failed!(error) record.update!( refreshing: false, last_error: error. ) end |
#mark_refreshed!(row_count:, duration_ms:) ⇒ 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.
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/activerecord/materialized/metadata.rb', line 117 def mark_refreshed!(row_count:, duration_ms:) record.update!( last_refreshed_at: Timestamps.current, refreshing: false, dirty: false, row_count: row_count, refresh_duration_ms: duration_ms, last_error: nil, maintenance_payload: nil ) end |
#mark_refreshing! ⇒ 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.
109 110 111 112 113 114 |
# File 'lib/activerecord/materialized/metadata.rb', line 109 def mark_refreshing! record.update!( refreshing: true, last_error: nil ) end |
#mark_warm! ⇒ 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.
74 75 76 |
# File 'lib/activerecord/materialized/metadata.rb', line 74 def mark_warm! record.update!(warm: true) end |
#record ⇒ 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.
29 30 31 32 |
# File 'lib/activerecord/materialized/metadata.rb', line 29 def record ensure_schema! MetadataRecord.find_or_initialize_by(view_name: view_class.view_key) end |
#record_maintenance_payload!(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.
94 95 96 |
# File 'lib/activerecord/materialized/metadata.rb', line 94 def record_maintenance_payload!(payload) MaintenancePayload.record!(self, payload) end |
#refresh_duration_ms ⇒ 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.
58 59 60 |
# File 'lib/activerecord/materialized/metadata.rb', line 58 def refresh_duration_ms record.refresh_duration_ms end |
#refreshing? ⇒ 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.
48 49 50 |
# File 'lib/activerecord/materialized/metadata.rb', line 48 def refreshing? !!record.refreshing? end |
#row_count ⇒ 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.
53 54 55 |
# File 'lib/activerecord/materialized/metadata.rb', line 53 def row_count record.row_count end |
#stale?(max_staleness: view_class.resolved_max_staleness) ⇒ 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.
79 80 81 82 83 84 85 86 |
# File 'lib/activerecord/materialized/metadata.rb', line 79 def stale?(max_staleness: view_class.resolved_max_staleness) return true if dirty? return true if last_refreshed_at.nil? return false if max_staleness.nil? refreshed_at = T.must(last_refreshed_at) refreshed_at.to_time < Timestamps.threshold(max_staleness).to_time end |
#warm? ⇒ 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.
69 70 71 |
# File 'lib/activerecord/materialized/metadata.rb', line 69 def warm? !!record.warm? end |