Class: Profiler::Api::ProfilesController

Inherits:
Profiler::ApplicationController show all
Defined in:
app/controllers/profiler/api/profiles_controller.rb

Instance Method Summary collapse

Instance Method Details

#clearObject



46
47
48
49
# File 'app/controllers/profiler/api/profiles_controller.rb', line 46

def clear
  Profiler.storage.clear(type: "http")
  head :no_content
end

#destroyObject



38
39
40
41
42
43
44
# File 'app/controllers/profiler/api/profiles_controller.rb', line 38

def destroy
  profile = Profiler.storage.load(params[:id])
  return render json: { error: "Profile not found" }, status: :not_found unless profile

  Profiler.storage.delete(params[:id])
  head :no_content
end

#indexObject



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/controllers/profiler/api/profiles_controller.rb', line 8

def index
  limit  = (params[:limit]  || 50).to_i
  offset = (params[:offset] || 0).to_i
  all    = Profiler.storage.list(limit: 1000, offset: 0)
  http   = all.reject { |p| p.profile_type == "job" }
  page   = http.drop(offset).first(limit + 1)
  render json: {
    profiles: page.first(limit).map(&:to_h),
    limit:    limit,
    offset:   offset,
    has_more: page.size > limit
  }
end

#showObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/profiler/api/profiles_controller.rb', line 22

def show
  profile = Profiler.storage.load(params[:id])

  unless profile
    return render json: { error: "Profile not found" }, status: :not_found
  end

  # Recalculate AJAX collector data (since AJAX requests happen after page load)
  recalculate_ajax_data(profile)

  render json: profile.to_h.merge(
    child_jobs: build_child_jobs(profile),
    parent_profile: build_parent_summary(profile)
  )
end