Class: Pipeloader::Source

Inherits:
GraphQL::Dataloader::Source
  • Object
show all
Defined in:
lib/pipeloader/source.rb

Overview

A GraphQL::Dataloader source that gathers every SELECT parked at a fiber tick and runs them as one pipelined burst, returning an ActiveRecord::Result per query (so AR builds models normally).

Instance Method Summary collapse

Constructor Details

#initialize(conn) ⇒ Source

conn: the AR connection threaded in from the call site (the QueryCache patch’s own connection, or the model’s in FusionSource). @pg drives the pipeline; @conn supplies the OID -> type lookup for building typed results.



9
10
11
12
# File 'lib/pipeloader/source.rb', line 9

def initialize(conn)
  @conn = conn
  @pg = conn.raw_connection
end

Instance Method Details

#fetch(keys) ⇒ Object

keys: array of [sql, params], deduplicated by Dataloader. Must return one result per key, in order.



16
17
18
19
20
21
# File 'lib/pipeloader/source.rb', line 16

def fetch(keys)
  batch = Pipeliner.pipeline_batch(@pg, keys)
  Pipeloader.round_trips += 1
  Pipeloader.queries += keys.size
  batch.map { |columns, rows, oids| to_ar_result(columns, rows, oids) }
end