$ show charkost/prosopite
Prosopite is a Ruby gem library that auto-detects N+1 queries in Rails applications with zero false positives/negatives. It monitors all SQL queries via ActiveSupport::Notifications, groups them by call stack and query fingerprint (normalized form), and reports when multiple queries from the same stack location share the same fingerprint. Unlike similar tools, it catches N+1s after record creations, first/last/pluck on collections, class changes (becomes), and across ORM boundaries (Mongoid calling ActiveRecord). The gem provides configurable notifications (Rails logger, custom logger, STDERR, raise exceptions) and middleware for Rack and Sidekiq. It supports both MySQL (built-in fingerprinting) and PostgreSQL (via pg_query gem) adapters. The architecture is a single module with thread-local state for scan mode, a subscription to sql.active_record, and a notification aggregator. It includes a comprehensive test suite using Minitest and FactoryBot against SQLite.
The LLM identified 1 files worth highlighting for reuse:
The `mysql_fingerprint` class method (lines ~120-180) is a standalone, dependency-free implementation of MySQL query fingerprinting/normalization. It strips comments, collapses literal values (strings, numbers, booleans, nulls), normalizes whitespace, handles special cases like IN lists, VALUES, UNION, LIMIT, and CALL statements. This method can be extracted into its own gem or utility module for any Ruby application that needs to group or analyze MySQL queries by their structural pattern. It is thoroughly tested in `test/test_mysql_fingerprint.rb` with 40+ edge cases, demonstrating robust handling of MySQL syntax variants.