Module: RSpeed::Splitter

Defined in:
lib/rspeed/splitter.rb

Class Method Summary collapse

Class Method Details

.append(items:, key:) ⇒ Object



11
12
13
# File 'lib/rspeed/splitter.rb', line 11

def append(items:, key:)
  items.each { |item| RSpeed::Redis.client.rpush(key, item) }
end

.consolidateObject



15
16
17
18
19
20
21
# File 'lib/rspeed/splitter.rb', line 15

def consolidate
  RSpeed::Logger.log(self, __method__, 'Consolidating profiles.')

  RSpeed::Redis.destroy(pattern: RSpeed::Variable.result)

  append(items: RSpeed::Redis.profiles_content, key: RSpeed::Variable.result)
end

.first_pipe?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/rspeed/splitter.rb', line 23

def first_pipe?
  RSpeed::Env.pipe == 1
end

.need_warm?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rspeed/splitter.rb', line 27

def need_warm?
  first_pipe? && !RSpeed::Redis.result?
end

.pipe_filesObject



31
32
33
34
35
36
37
38
39
# File 'lib/rspeed/splitter.rb', line 31

def pipe_files
  return unless RSpeed::Redis.result?

  splitted = split(data: RSpeed::Differ.diff[:actual_files])

  splitted[RSpeed::Variable.key(RSpeed::Env.pipe)][:files].tap do |items|
    RSpeed::Reporter.print_files(items)
  end.map { |item| item[:file] }.join(' ')
end

.split(data:) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rspeed/splitter.rb', line 41

def split(data:)
  json = {}

  RSpeed::Env.pipes.times do |index|
    json[RSpeed::Variable.key(index + 1)] ||= []
    json[RSpeed::Variable.key(index + 1)] = { total: 0, files: [], number: index + 1 }
  end

  sorted_data = data.sort_by { |item| item[:time] || 0.0 }.reverse

  sorted_data.each do |record|
    selected_pipe_data = json.min_by { |pipe| pipe[1][:total] }
    selected_pipe      = json[RSpeed::Variable.key(selected_pipe_data[1][:number])]
    time               = record[:time].to_f

    selected_pipe[:total] += time
    selected_pipe[:files] << { file: record[:file], time: time }
  end

  json
end