Sha256: 9483d2983fd31c4b34e5627591c384ebe94bac123b0a411c1b7d990f948e9fc6

Contents?: true

Size: 834 Bytes

Versions: 71

Compression:

Stored size: 834 Bytes

Contents

module Scrivito
class ObjSearchEnumerator
  class BatchIterator
    def initialize(workspace, query, initial_batch)
      @query = query
      @executor = ObjSearchEnumerator::QueryExecutor.new(workspace)
      @all_fetched_ids = Set.new
      @initial_batch = initial_batch
    end

    attr_reader :total

    def each
      current_batch = initial_batch || fetch_batch

      loop do
        yield current_batch
        break unless current_batch.continuation
        current_batch = fetch_batch(current_batch.continuation)
      end

      @total = @all_fetched_ids.size
    end

    private

    attr_reader :query, :executor, :initial_batch

    def fetch_batch(continuation=nil)
      batch = executor.call(query, continuation, @all_fetched_ids)
      @all_fetched_ids += batch.objs.map(&:id)
      batch
    end
  end
end
end

Version data entries

71 entries across 71 versions & 1 rubygems

Version Path
scrivito_sdk-1.13.0 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.13.0.rc2 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.13.0.rc1 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.12.0 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.12.0.rc2 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.12.0.rc1 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.11.0 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.11.0.rc1 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.10.0 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.10.0.rc5 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.10.0.rc4 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.10.0.rc3 app/cms/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.10.0.rc2 lib/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.10.0.rc1 lib/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.9.1 lib/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.9.1.rc1 lib/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.9.0 lib/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.9.0.rc2 lib/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.9.0.rc1 lib/scrivito/obj_search_enumerator/batch_iterator.rb
scrivito_sdk-1.8.1 lib/scrivito/obj_search_enumerator/batch_iterator.rb