class NoSE::Loader::RandomLoader

Load some random data (mostly useful for testing)

Public Class Methods

new(workload = nil, backend = nil) click to toggle source
# File lib/nose/loader/random.rb, line 7
def initialize(workload = nil, backend = nil)
  @logger = Logging.logger['nose::loader::randomloader']

  @workload = workload
  @backend = backend
end

Public Instance Methods

load(indexes, config, show_progress = false, limit = nil, skip_existing = true) click to toggle source

Load a generated set of indexes with data from MySQL @return [void]

# File lib/nose/loader/random.rb, line 16
def load(indexes, config, show_progress = false, limit = nil,
         skip_existing = true)
  limit = 1 if limit.nil?

  indexes.map!(&:to_id_graph).uniq! if @backend.by_id_graph
  indexes.uniq.each do |index|
    load_index index, config, show_progress, limit, skip_existing
  end
end

Private Instance Methods

load_index(index, _config, show_progress, limit, skip_existing) click to toggle source

Load a single index into the backend @return [void]

# File lib/nose/loader/random.rb, line 30
def load_index(index, _config, show_progress, limit, skip_existing)
  # Skip this index if it's not empty
  if skip_existing && !@backend.index_empty?(index)
    @logger.info "Skipping index #{index.inspect}" if show_progress
    return
  end
  @logger.info index.inspect if show_progress

  chunk = Array.new(limit) do
    Hash[index.all_fields.map do |field|
      [field.id, field.random_value]
    end]
  end

  @backend.index_insert_chunk index, chunk
end