charkost / prosopite

:mag: Rails N+1 queries auto-detection with zero false positives / false negatives
Apache License 2.0
1.48k stars 45 forks source link

Support trilogy mysql adapter #67

Closed dhruvCW closed 11 months ago

dhruvCW commented 1 year ago

Check if the adapter is mysql or trilogy to decide if the fingerprinting should be mysql or postgresql. trilogy is a new mysql adapter for ruby.

more info here https://github.com/trilogy-libraries

trilogy will also be a bundled adapter from rails 7.1

dhruvCW commented 1 year ago

@charkost would be awesome if we could release this once merged 😁 🍻

BrianHawley commented 12 months ago

Hotpatch initializer version:

# frozen_string_literal: true

if defined?(Prosopite)
  begin
    Prosopite.fingerprint("select 1")
  rescue LoadError
    # Add support for the trilogy adapter.
    Prosopite.module_exec do
      class << self
        def fingerprint(query)
          if ActiveRecord::Base.connection.adapter_name.downcase.start_with?("mysql", "trilogy")
            mysql_fingerprint(query)
          else
            begin
              require "pg_query"
            rescue LoadError => e
              msg = "Could not load the 'pg_query' gem. Add `gem 'pg_query'` to your Gemfile"
              raise LoadError, msg, e.backtrace
            end
            PgQuery.fingerprint(query)
          end
        end
      end
    end
  end
end
charkost commented 11 months ago

Thanks @dhruvCW !