Class: ActiveRecord::AsynchronousQueriesTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/asynchronous_queries_tracker.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Session

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAsynchronousQueriesTracker

Returns a new instance of AsynchronousQueriesTracker.



45
46
47
# File 'lib/active_record/asynchronous_queries_tracker.rb', line 45

def initialize
  @stack = []
end

Class Method Details

.complete(asynchronous_queries_tracker) ⇒ Object



40
41
42
# File 'lib/active_record/asynchronous_queries_tracker.rb', line 40

def complete(asynchronous_queries_tracker)
  asynchronous_queries_tracker.finalize_session
end

.install_executor_hooks(executor = ActiveSupport::Executor) ⇒ Object



32
33
34
# File 'lib/active_record/asynchronous_queries_tracker.rb', line 32

def install_executor_hooks(executor = ActiveSupport::Executor)
  executor.register_hook(self)
end

.runObject



36
37
38
# File 'lib/active_record/asynchronous_queries_tracker.rb', line 36

def run
  ActiveRecord::Base.asynchronous_queries_tracker.tap(&:start_session)
end

Instance Method Details

#current_sessionObject



49
50
51
# File 'lib/active_record/asynchronous_queries_tracker.rb', line 49

def current_session
  @stack.last or raise ActiveRecordError, "Can't perform asynchronous queries without a query session"
end

#finalize_session(wait = false) ⇒ Object



58
59
60
61
62
# File 'lib/active_record/asynchronous_queries_tracker.rb', line 58

def finalize_session(wait = false)
  session = @stack.pop
  session&.finalize(wait)
  self
end

#start_sessionObject



53
54
55
56
# File 'lib/active_record/asynchronous_queries_tracker.rb', line 53

def start_session
  session = Session.new
  @stack << session
end