module FogTracker

  # Tracks a single Fog collection in a single account
  class ResourceTracker

    attr_accessor :collection

    # Creates an object for tracking a single Fog collection in a single account
    #
    # ==== Attributes
    #
    # * +resource_type+ - the Fog collection name (String) for this resource type
    # * +account_tracker+ - the AccountTracker for this tracker's @collection
    def initialize(resource_type, account_tracker)
      @type             = resource_type
      @account_tracker  = account_tracker
      @account          = account_tracker.account
      @account_name     = account_tracker.name
      @log              = account_tracker.log
      @collection       = Array.new
      @log.debug "Created tracker for #{@type} on #{@account_name}."
    end

    # Polls the account's connection for updated info on all existing
    # instances of the relevant resource type, and saves them as @collection
    def update
      @log.info "Polling #{@type} on #{@account_name}..."
      @collection = @account_tracker.connection.send(@type)
      @log.info "Discovered #{@collection.count} #{@type} on #{@account_name}."
    end

  end
end

module FogTracker

  # Tracks a single Fog collection in a single account
  class ResourceTracker

    attr_accessor :collection

    # Creates an object for tracking a single Fog collection in a single account
    #
    # ==== Attributes
    #
    # * +resource_type+ - the Fog collection name (String) for this resource type
    # * +account_tracker+ - the AccountTracker for this tracker's @collection
    def initialize(resource_type, account_tracker)
      @type             = resource_type
      @account_tracker  = account_tracker
      @account          = account_tracker.account
      @account_name     = account_tracker.name
      @log              = account_tracker.log
      @collection       = Array.new
      @log.debug "Created tracker for #{@type} on #{@account_name}."
    end

    # Polls the account's connection for updated info on all existing
    # instances of the relevant resource type, and saves them as @collection
    def update
      @log.info "Polling #{@type} on #{@account_name}..."
      fog_collection = @account_tracker.connection.send(@type) || Array.new
      @log.info "Fetching #{fog_collection.count} #{@type} on #{@account_name}."
      new_collection = Array.new
      # Here's where most of the network overhead is actually incurred
      fog_collection.each do |resource|
        @log.debug "Fetching resource: #{resource.class} #{resource.identity}"
        new_collection << resource
        @log.debug "Got resource: #{resource.inspect}"
      end
      @collection = new_collection
    end

  end
end

Fix improper deferral of network overhead to Query layer with large data sets
Fix improper deferral of network overhead to Query layer with large data sets