Class: Profiler::Collectors::AjaxCollector

Inherits:
BaseCollector show all
Defined in:
lib/profiler/collectors/ajax_collector.rb

Instance Attribute Summary

Attributes inherited from BaseCollector

#profile

Instance Method Summary collapse

Methods inherited from BaseCollector

descendants, #has_data?, inherited, #initialize, #name, #panel_content, #render_html, #render_mode

Constructor Details

This class inherits a constructor from Profiler::Collectors::BaseCollector

Instance Method Details

#collectObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/profiler/collectors/ajax_collector.rb', line 31

def collect
  # Query storage for child AJAX profiles
  ajax_profiles = Profiler.storage.find_by_parent(@profile.token)

  return store_data({}) if ajax_profiles.empty?

  # Generate summary statistics
  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

#iconObject



8
9
10
# File 'lib/profiler/collectors/ajax_collector.rb', line 8

def icon
  "🌐"
end

#priorityObject



12
13
14
# File 'lib/profiler/collectors/ajax_collector.rb', line 12

def priority
  25
end

#subscribeObject



27
28
29
# File 'lib/profiler/collectors/ajax_collector.rb', line 27

def subscribe
  # Passive collector - no subscriptions needed
end

#tab_configObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/profiler/collectors/ajax_collector.rb', line 16

def tab_config
  {
    key: "ajax",
    label: "AJAX",
    icon: icon,
    priority: priority,
    enabled: true,
    default_active: false
  }
end

#toolbar_summaryObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/profiler/collectors/ajax_collector.rb', line 49

def toolbar_summary
  return "" unless @data && @data["total_requests"]&.positive?

  total = @data["total_requests"]
  duration = @data["total_duration"]

  # Color coding based on number of requests
  color = if total > 20
            "orange"
          elsif total > 50
            "red"
          else
            "green"
          end

  {
    text: "#{total} AJAX (#{duration}ms)",
    color: color
  }
end