Sha256: 99a01f1adff66e1dc170625ab8113c3b3886820430a20a85ab48ca922408cdd3

Contents?: true

Size: 851 Bytes

Versions: 4

Compression:

Stored size: 851 Bytes

Contents

# frozen_string_literal: true

module RailsMiniProfiler
  module Tracing
    class SqlTracker
      TRACKED_SQL_COMMANDS = %w[SELECT INSERT UPDATE DELETE].freeze
      UNTRACKED_NAMES = %w[SCHEMA].freeze
      UNTRACKED_TABLES = %w[
        SCHEMA_MIGRATIONS
        SQLITE_MASTER
        ACTIVE_MONITORING_METRICS
        SQLITE_TEMP_MASTER
        SQLITE_VERSION
        AR_INTERNAL_METADATA
      ].freeze

      def initialize(query:, name:)
        @query = query.to_s.upcase
        @name = name.to_s.upcase
      end

      def track?
        query.start_with?(*TRACKED_SQL_COMMANDS) &&
          !name.start_with?(*UNTRACKED_NAMES) &&
          !untracked_tables?
      end

      private

      attr_reader :query, :name

      def untracked_tables?
        UNTRACKED_TABLES.any? { |table| query.include?(table) }
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rails_mini_profiler-0.7.0 lib/rails_mini_profiler/tracing/sequel_tracker.rb
rails_mini_profiler-0.6.0 lib/rails_mini_profiler/tracing/sequel_tracker.rb
rails_mini_profiler-0.5.0 lib/rails_mini_profiler/tracing/sequel_tracker.rb
rails_mini_profiler-0 lib/rails_mini_profiler/tracing/sequel_tracker.rb