Class: MatViews::Services::ConcurrentRefresh

Inherits:
BaseService
  • Object
show all
Defined in:
lib/mat_views/services/concurrent_refresh.rb

Overview

Refresh service that runs:

`REFRESH MATERIALIZED VIEW CONCURRENTLY <schema>.<rel>`

It keeps the view readable during refresh, but **requires at least one UNIQUE index** on the materialised view (a PostgreSQL constraint).

Options:

  • row_count_strategy: (Symbol, default: :none) → one of :estimated, :exact, or ‘:none or nil` to control row count reporting

Returns a MatViews::ServiceResponse

Examples:

Direct usage

svc = MatViews::Services::ConcurrentRefresh.new(definition, **options)
response = svc.call
response.success? # => true/false

via job, this is the typical usage and will create a run record in the DB

When definition.refresh_strategy == "concurrent"
MatViews::Jobs::Adapter.enqueue(MatViews::Services::RefreshViewJob, definition.id, **options)

See Also:

Constant Summary

Constants inherited from BaseService

BaseService::ALLOWED_ROW_STRATEGIES, BaseService::DEFAULT_NIL_STRATEGY, BaseService::DEFAULT_ROW_STRATEGY, BaseService::UNKNOWN_ROW_COUNT

Instance Attribute Summary

Attributes inherited from BaseService

#definition, #request, #response, #row_count_strategy, #use_transaction

Instance Method Summary collapse

Methods inherited from BaseService

#call

Constructor Details

#initialize(definition, row_count_strategy: :estimated) ⇒ ConcurrentRefresh

Returns a new instance of ConcurrentRefresh.



36
37
38
39
# File 'lib/mat_views/services/concurrent_refresh.rb', line 36

def initialize(definition, row_count_strategy: :estimated)
  super
  @use_transaction = false
end