Sha256: 741feb16ab8e226a565c0a4baba8da03d67b486a70a0612667fa7d5245af88b1

Contents?: true

Size: 1.11 KB

Versions: 10

Compression:

Stored size: 1.11 KB

Contents

module ActiveTracker
  class QueriesController < ActiveTracker::BaseController
    def index
      ts = Time.current.to_f
      @queries = ActiveTracker::Model.all("Query")
      filter_queries if params[:q].present?
      duration = (Time.current.to_f - ts) * 1000
      @queries, @pagination = ActiveTracker::Model.paginate(@queries, params[:page], ActiveTracker::Configuration.per_page)
      @duration = duration
    end

    def show
      @query = ActiveTracker::Model.find(params[:id])
      @requests = @query.at_requests.map {|id| ActiveTracker::Model.find(id) rescue nil}.compact
    end

    private

    def filter_queries
      filters = params[:q].split(/\s+/)
      filtered = @queries.select do |query|
        acceptable = true
        filters.each do |filter|
          if filter[":"]
            key,value = filter.split(":")
            if query.tags[key.to_sym]&.downcase != value&.downcase
              acceptable = false
            end
          else
            acceptable = false unless query.tags[:sql][filter]
          end
        end
        acceptable
      end
      @queries = filtered
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
activetracker-0.4.9 app/controllers/active_tracker/queries_controller.rb
activetracker-0.4.8 app/controllers/active_tracker/queries_controller.rb
activetracker-0.4.7 app/controllers/active_tracker/queries_controller.rb
activetracker-0.4.6 app/controllers/active_tracker/queries_controller.rb
activetracker-0.4.5 app/controllers/active_tracker/queries_controller.rb
activetracker-0.4.4 app/controllers/active_tracker/queries_controller.rb
activetracker-0.4.3 app/controllers/active_tracker/queries_controller.rb
activetracker-0.4.2 app/controllers/active_tracker/queries_controller.rb
activetracker-0.4.1 app/controllers/active_tracker/queries_controller.rb
activetracker-0.4.0 app/controllers/active_tracker/queries_controller.rb