Class: ActiveRecordDataLoader::TableLoader
- Inherits:
-
Object
- Object
- ActiveRecordDataLoader::TableLoader
- Defined in:
- lib/active_record_data_loader/table_loader.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(logger:, connection_handler:, strategy:) ⇒ TableLoader
constructor
A new instance of TableLoader.
- #load_data(batch_size, total_rows) ⇒ Object
Constructor Details
#initialize(logger:, connection_handler:, strategy:) ⇒ TableLoader
Returns a new instance of TableLoader.
18 19 20 21 22 |
# File 'lib/active_record_data_loader/table_loader.rb', line 18 def initialize(logger:, connection_handler:, strategy:) @logger = logger @connection_handler = connection_handler @strategy = strategy end |
Class Method Details
.load_data(total_rows:, batch_size:, logger:, connection_handler:, strategy:) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/active_record_data_loader/table_loader.rb', line 7 def self.load_data( total_rows:, batch_size:, logger:, connection_handler:, strategy: ) new(logger: logger, connection_handler: connection_handler, strategy: strategy) .load_data(batch_size, total_rows) end |
Instance Method Details
#load_data(batch_size, total_rows) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/active_record_data_loader/table_loader.rb', line 24 def load_data(batch_size, total_rows) batch_count = (total_rows / batch_size.to_f).ceil logger.info( "[ActiveRecordDataLoader] "\ "Loading #{total_rows} row(s) into '#{strategy.table_name}' via #{strategy.name}. "\ "#{batch_size} row(s) per batch, #{batch_count} batch(es)." ) total_time = Benchmark.realtime do load_in_batches(batch_size, total_rows, batch_count) end logger.info( "[ActiveRecordDataLoader] "\ "Completed loading #{total_rows} row(s) into '#{strategy.table_name}' "\ "in #{total_time} seconds." ) end |