class MysqlDumpSlow::SlowLog

Public Class Methods

new(logs) click to toggle source
# File lib/mysql_dump_slow/slow_log.rb, line 3
def initialize(logs)
  @logs = logs
end

Public Instance Methods

find_each(options={}) { |log| ... } click to toggle source
# File lib/mysql_dump_slow/slow_log.rb, line 7
def find_each(options={})
  return @logs.each{ |log| yield log } unless active_record_relation?

  find_in_batches(options) do |records|
    records.each { |record| yield record }
  end
end
find_in_batches(options={}) { |log| ... } click to toggle source
# File lib/mysql_dump_slow/slow_log.rb, line 15
def find_in_batches(options={})
  return @logs.each{ |log| yield log } unless active_record_relation?

  batch_order = options[:batch_order] || :start_time
  batch_size  = options[:batch_size]  || 1000

  relation = @logs
  relation = relation.reorder(batch_order).limit(batch_size)
  records  = relation.to_a

  while records.any?
    records_size = records.size
    primary_key_offset = records.last.start_time

    yield records

    break if records_size < batch_size

    records = relation.where("#{batch_order} > ?", primary_key_offset).to_a
  end
end

Private Instance Methods

active_record_relation?() click to toggle source
# File lib/mysql_dump_slow/slow_log.rb, line 39
def active_record_relation?
  defined?(ActiveRecord::Relation) && @logs.is_a?(ActiveRecord::Relation)
end