explaingit

flyerhzm/bullet

7,313RubyAudience · developerComplexity · 2/5Setup · easy

TLDR

Ruby gem for Rails that detects slow database patterns during development, like N+1 queries, and tells you exactly which line of code to fix and how.

Mindmap

mindmap
  root((Bullet))
    What it detects
      N+1 queries
      Unused eager loading
      Missing counter caches
    Notification channels
      Browser alert
      Log file
      Slack
    Tech Stack
      Ruby
      Rails
      ActiveRecord
    Audience
      Rails developers
      Backend engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Catch N+1 database queries in a Rails app during development before they reach production and slow down real users.

USE CASE 2

Find and remove unnecessary eager loading that pre-fetches data no template ever reads.

USE CASE 3

Get Slack or browser notifications the moment new database inefficiencies appear while you browse the app.

USE CASE 4

Identify where adding a counter cache would speed up a page that counts associated records repeatedly.

Tech stack

RubyRailsActiveRecordMongoid

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

Bullet is a Ruby gem that watches your web application while you work on it and warns you when the database is being used inefficiently. It is designed for use during development, not in production, so the alerts stay internal to your team. The main problem it targets is called an N+1 query. This happens when your application loads a list of items, then separately queries the database for each item's related data, one by one. For example, loading 100 blog posts and then making 100 separate requests to get each post's comments is an N+1 pattern. Instead of 101 database calls, the application could make just 2. Bullet detects when this is happening and tells you exactly which piece of code is causing it and how to fix it. Bullet also catches the opposite problem: eager loading that was added to improve performance but is not actually being used. If your code is pre-fetching related data that nothing on the page ever reads, Bullet flags it so you can remove the unnecessary work. It can also suggest when a counter cache, a way to store a running count in the database rather than recounting each time, would speed things up. When it detects an issue, Bullet can notify you in several ways: a pop-up alert in the browser, a note in the browser's developer console, a log file, a footer added to the bottom of your page, or via third-party services like Slack, Sentry, or Honeybadger. You choose which notification channels to enable in the configuration. The gem works with ActiveRecord version 4.0 and above, and with Mongoid version 4.0 and above. It can be added to a Rails project with a single generator command, and individual detectors can be turned off if needed. You can also add specific queries to a safe list to suppress warnings for issues you are aware of and have chosen not to fix.

Copy-paste prompts

Prompt 1
I'm adding the Bullet gem to my Rails 7 app. Write me the initializer config that enables N+1 detection and sends alerts to both the browser console and a log file.
Prompt 2
Bullet flagged an N+1 query on my Post model when loading its comments. Show me how to fix it with the correct Rails eager loading syntax.
Prompt 3
My Rails app pre-fetches user data with includes but Bullet says it's unused eager loading. Explain what that means and how to remove the unnecessary query.
Prompt 4
Set up Bullet in a Rails app to send N+1 query warnings to a Slack channel using the Slack notification integration.
Open on GitHub → Explain another repo

← flyerhzm on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.