Class: Lhm::IdSetChunkFinder
- Inherits:
-
Object
- Object
- Lhm::IdSetChunkFinder
- Defined in:
- lib/lhm/id_set_chunk_finder.rb
Constant Summary collapse
- LOG_PREFIX =
"Chunker"
Instance Method Summary collapse
- #each_chunk ⇒ Object
-
#initialize(migration, connection = nil, options = {}) ⇒ IdSetChunkFinder
constructor
A new instance of IdSetChunkFinder.
- #max_rows ⇒ Object
- #processed_rows ⇒ Object
- #table_empty? ⇒ Boolean
- #validate ⇒ Object
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, = {}) @migration = migration @connection = connection @ids = [:ids] @throttler = [:throttler] @processed_rows = 0 end |
Instance Method Details
#each_chunk ⇒ Object
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_rows ⇒ Object
33 34 35 |
# File 'lib/lhm/id_set_chunk_finder.rb', line 33 def max_rows ids.length end |
#processed_rows ⇒ Object
37 38 39 |
# File 'lib/lhm/id_set_chunk_finder.rb', line 37 def processed_rows @processed_rows end |
#table_empty? ⇒ Boolean
15 16 17 |
# File 'lib/lhm/id_set_chunk_finder.rb', line 15 def table_empty? ids.nil? || ids.empty? end |
#validate ⇒ Object
19 20 |
# File 'lib/lhm/id_set_chunk_finder.rb', line 19 def validate end |