fix balances query n+1
This commit is contained in:
18
app/graphql/sources/active_record.rb
Normal file
18
app/graphql/sources/active_record.rb
Normal file
@@ -0,0 +1,18 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Sources
|
||||
class ActiveRecord < GraphQL::Dataloader::Source
|
||||
# rubocop:disable Lint/MissingSuper
|
||||
def initialize(model_class)
|
||||
@model_class = model_class
|
||||
end
|
||||
|
||||
def fetch(ids)
|
||||
@model_class
|
||||
.where(id: ids)
|
||||
.index_by(&:id)
|
||||
.slice(*ids)
|
||||
.values
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user