Sha256: e21b0d586849f19d28f0db17f5cf28b9ccf95a81e6ad589d2c051637b1cc3e60

Contents?: true

Size: 1.97 KB

Versions: 6

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

require_dependency 'rails_mini_profiler/application_controller'

module RailsMiniProfiler
  class ProfiledRequestsController < ApplicationController
    before_action :set_profiled_request, only: %i[show destroy]

    def index
      @profiled_requests = ProfiledRequest
                             .includes(:flamegraph)
                             .where(user_id: user_id).order(id: :desc)
      @profiled_requests = @profiled_requests.where('request_path LIKE ?', "%#{params[:path]}%") if params[:path]
      @profiled_requests = @profiled_requests.map { |request| present(request) }
    end

    def show
      @traces = @profiled_request.traces
      @traces = @traces.where('payload LIKE ?', "%#{params[:search]}%") if params[:search]
      @traces = @traces
                  .order(:start)
                  .map { |trace| present(trace, profiled_request: @profiled_request) }
      @profiled_request = present(@profiled_request)
    end

    def destroy
      ProfiledRequest.where(user_id: user_id).destroy(@profiled_request.id)
      redirect_to profiled_requests_url, notice: 'Profiled request was successfully destroyed.'
    end

    def destroy_all
      ProfiledRequest.transaction do
        requests_table_name = RailsMiniProfiler.storage_configuration.profiled_requests_table.to_sym
        Flamegraph.joins(:profiled_request).where(requests_table_name => { user_id: user_id }).delete_all
        Trace.joins(:profiled_request).where(requests_table_name => { user_id: user_id }).delete_all
        ProfiledRequest.where(requests_table_name => { user_id: user_id }).delete_all
      end
      redirect_to profiled_requests_url, notice: 'Profiled Requests cleared'
    end

    private

    def user_id
      @user_id ||= User.get(request.env)
    end

    def set_profiled_request
      @profiled_request = ProfiledRequest.where(user_id: user_id).find(params[:id])
    end

    def configuration
      @configuration ||= RailsMiniProfiler.configuration
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails_mini_profiler-0.2.1 app/controllers/rails_mini_profiler/profiled_requests_controller.rb
rails_mini_profiler-0.2.0 app/controllers/rails_mini_profiler/profiled_requests_controller.rb
rails_mini_profiler-0.1.3 app/controllers/rails_mini_profiler/profiled_requests_controller.rb
rails_mini_profiler-0.1.2 app/controllers/rails_mini_profiler/profiled_requests_controller.rb
rails_mini_profiler-0.1.1 app/controllers/rails_mini_profiler/profiled_requests_controller.rb
rails_mini_profiler-0.1.0 app/controllers/rails_mini_profiler/profiled_requests_controller.rb