Class: Profiler::Collectors::AjaxCollector
Instance Attribute Summary
#profile
Instance Method Summary
collapse
descendants, #has_data?, inherited, #name, #panel_content, #render_html, #render_mode
Constructor Details
#initialize(profile, storage: Profiler.storage) ⇒ AjaxCollector
Returns a new instance of AjaxCollector.
8
9
10
11
|
# File 'lib/profiler/collectors/ajax_collector.rb', line 8
def initialize(profile, storage: Profiler.storage)
super(profile)
@storage = storage
end
|
Instance Method Details
#collect ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/profiler/collectors/ajax_collector.rb', line 36
def collect
ajax_profiles = @storage.find_by_parent(@profile.token)
return store_data({}) if ajax_profiles.empty?
data = {
"total_requests" => ajax_profiles.size,
"total_duration" => ajax_profiles.sum(&:duration).round(2),
"by_method" => group_by_method(ajax_profiles),
"by_status" => group_by_status(ajax_profiles),
"requests" => ajax_profiles.map { |p| request_summary(p) }
}
store_data(data)
end
|
#icon ⇒ Object
13
14
15
|
# File 'lib/profiler/collectors/ajax_collector.rb', line 13
def icon
"🌐"
end
|
#priority ⇒ Object
17
18
19
|
# File 'lib/profiler/collectors/ajax_collector.rb', line 17
def priority
25
end
|
#subscribe ⇒ Object
32
33
34
|
# File 'lib/profiler/collectors/ajax_collector.rb', line 32
def subscribe
end
|
#tab_config ⇒ Object
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/profiler/collectors/ajax_collector.rb', line 21
def tab_config
{
key: "ajax",
label: "AJAX",
icon: icon,
priority: priority,
enabled: true,
default_active: false
}
end
|
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/profiler/collectors/ajax_collector.rb', line 53
def toolbar_summary
return "" unless @data && @data["total_requests"]&.positive?
total = @data["total_requests"]
duration = @data["total_duration"]
color = if total > 20
"orange"
elsif total > 50
"red"
else
"green"
end
{
text: "#{total} AJAX (#{duration}ms)",
color: color
}
end
|