Sha256: 7d32140a012e5eb6ce44a43ca66089b1a2b511b69d934bdb12529a1504e0e27b

Contents?: true

Size: 1015 Bytes

Versions: 9

Compression:

Stored size: 1015 Bytes

Contents

# frozen_string_literal: true

module PgEventstore
  # @!visibility private
  class Preloader
    attr_reader :connection
    private :connection

    # @param connection [PgEventstore::Connection]
    def initialize(connection)
      @connection = connection
    end

    # @param raw_events [Array<Hash>]
    # @return [Array<Hash>]
    def preload_related_objects(raw_events)
      streams = stream_queries.find_by_ids(raw_events.map { _1['stream_id'] }).to_h { [_1['id'], _1] }
      types = event_type_queries.find_by_ids(raw_events.map { _1['event_type_id'] }).to_h { [_1['id'], _1] }
      raw_events.each do |event|
        event['stream'] = streams[event['stream_id']]
        event['type'] = types[event['event_type_id']]['type']
      end
    end

    private

    # @return [PgEventstore::EventTypeQueries]
    def event_type_queries
      EventTypeQueries.new(connection)
    end

    # @return [PgEventstore::StreamQueries]
    def stream_queries
      StreamQueries.new(connection)
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pg_eventstore-0.9.0 lib/pg_eventstore/queries/preloader.rb
pg_eventstore-0.8.0 lib/pg_eventstore/queries/preloader.rb
pg_eventstore-0.7.2 lib/pg_eventstore/queries/preloader.rb
pg_eventstore-0.7.1 lib/pg_eventstore/queries/preloader.rb
pg_eventstore-0.7.0 lib/pg_eventstore/queries/preloader.rb
pg_eventstore-0.6.0 lib/pg_eventstore/queries/preloader.rb
pg_eventstore-0.5.3 lib/pg_eventstore/queries/preloader.rb
pg_eventstore-0.5.2 lib/pg_eventstore/queries/preloader.rb
pg_eventstore-0.5.0 lib/pg_eventstore/queries/preloader.rb