Sha256: 40b0dbbacb1a3c5b01738249627d1c7883886f89917d5c3e47da2a78982290ba

Contents?: true

Size: 461 Bytes

Versions: 7

Compression:

Stored size: 461 Bytes

Contents

# frozen_string_literal: true

module Ibrain
  module Loaders
    class CountLoader < GraphQL::Batch::Loader
      def initialize(model, field)
        super()
        @model = model
        @field = field
      end

      def perform(ids)
        counts = @model.unscoped.where(@field => ids).group(@field).count

        counts.each { |id, count| fulfill(id, count) }
        ids.each { |id| fulfill(id, 0) unless fulfilled?(id) }
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ibrain-core-0.5.15 app/graphql/ibrain/loaders/count_loader.rb
ibrain-core-0.5.13 app/graphql/ibrain/loaders/count_loader.rb
ibrain-core-0.5.12 app/graphql/ibrain/loaders/count_loader.rb
ibrain-core-0.5.10 app/graphql/ibrain/loaders/count_loader.rb
ibrain-core-0.5.9 app/graphql/ibrain/loaders/count_loader.rb
ibrain-core-0.5.8 app/graphql/ibrain/loaders/count_loader.rb
ibrain-core-0.5.7 app/graphql/ibrain/loaders/count_loader.rb