fix balances query n+1

This commit is contained in:
João Geonizeli
2021-08-11 21:45:15 -03:00
parent ee5edeb9a1
commit 5fc02f00f8
3 changed files with 24 additions and 1 deletions

View 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