Module: Pipeloader::ARPatch::Methods
- Defined in:
- lib/pipeloader/ar_patch.rb
Instance Attribute Summary collapse
-
#pipeloader_dataloader ⇒ Object
The active dataloader is stashed on the connection for the duration of the response phase (set/cleared by Pipeloader::Trace).
Instance Method Summary collapse
Instance Attribute Details
#pipeloader_dataloader ⇒ Object
The active dataloader is stashed on the connection for the duration of the response phase (set/cleared by Pipeloader::Trace). The connection is the pipelining unit and is shared across the request’s resolver fibers, so this is both the natural home and reliably visible here as ‘self`.
20 21 22 |
# File 'lib/pipeloader/ar_patch.rb', line 20 def pipeloader_dataloader @pipeloader_dataloader end |
Instance Method Details
#select_all(arel, name = nil, binds = [], preparable: nil, async: false, allow_retry: false) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/pipeloader/ar_patch.rb', line 22 def select_all(arel, name = nil, binds = [], preparable: nil, async: false, allow_retry: false) dl = pipeloader_dataloader if dl.is_a?(GraphQL::Dataloader) && !in_transaction? relation = arel_from_relation(arel) sql, bind_objs, = to_sql_and_binds(relation, binds, preparable, allow_retry) if sql.lstrip[0, 6].casecmp("select").zero? params = bind_objs.map { |b| b.respond_to?(:value_for_database) ? b.value_for_database : b } return dl.with(Pipeloader::Source, raw_connection).load([sql, params]) end end # Synchronous fallback (no active response, or not gathered): one query, # one round trip. result = super Pipeloader.round_trips += 1 Pipeloader.queries += 1 result end |