Class: Lhm::IdSetChunkFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/lhm/id_set_chunk_finder.rb

Constant Summary collapse

LOG_PREFIX =
"Chunker"

Instance Method Summary collapse

Constructor Details

#initialize(migration, connection = nil, options = {}) ⇒ IdSetChunkFinder

Returns a new instance of IdSetChunkFinder.



7
8
9
10
11
12
13
# File 'lib/lhm/id_set_chunk_finder.rb', line 7

def initialize(migration, connection = nil, options = {})
  @migration = migration
  @connection = connection
  @ids = options[:ids]
  @throttler = options[:throttler]
  @processed_rows = 0
end

Instance Method Details

#each_chunkObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/lhm/id_set_chunk_finder.rb', line 22

def each_chunk
  @processed_rows = 0
  while @processed_rows < ids.length
    next_idx = [@processed_rows + @throttler.stride, @ids.length].min
    range = @processed_rows...next_idx
    ids_to_insert = ids[range]
    @processed_rows = next_idx
    yield ChunkInsert.new(@migration, @connection, ids_to_insert[0], ids_to_insert[-1], expected_rows: range.count)
  end
end

#max_rowsObject



33
34
35
# File 'lib/lhm/id_set_chunk_finder.rb', line 33

def max_rows
  ids.length
end

#processed_rowsObject



37
38
39
# File 'lib/lhm/id_set_chunk_finder.rb', line 37

def processed_rows
  @processed_rows
end

#table_empty?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/lhm/id_set_chunk_finder.rb', line 15

def table_empty?
  ids.nil? || ids.empty?
end

#validateObject



19
20
# File 'lib/lhm/id_set_chunk_finder.rb', line 19

def validate
end