Module: Pipeloader::Trace

Defined in:
lib/pipeloader.rb

Overview

Stash the active dataloader on the connection for the whole response phase, and clear it at the end. This is done at multiplex scope, not per-query, because under Dataloader resolution is deferred to the multiplex’s fiber run loop — a per-query hook would clear the stash before resolvers ever run.

Instance Method Summary collapse

Instance Method Details

#execute_multiplex(multiplex:) ⇒ Object



61
62
63
64
65
66
67
68
69
70
# File 'lib/pipeloader.rb', line 61

def execute_multiplex(multiplex:)
  Pipeloader.reset_stats!
  conn = ActiveRecord::Base.connection
  # Raises on an unsupported adapter; on SQLite, leaves the stash unset so
  # select_all never pipelines (column projection still applies).
  conn.pipeloader_dataloader = multiplex.dataloader if Pipeloader.pipelining_supported?(conn)
  super
ensure
  conn.pipeloader_dataloader = nil if conn
end