Why this matters
Reduces query count and latency.
Use joins for filtering on associations and includes/preload for eager-loading to avoid N+1.
Reduces query count and latency.
Side-by-side examples engineers can pattern-match during review.
posts.each { |p| puts p.user.name }posts = Post.includes(:user)
posts.each { |p| puts p.user.name }User.where(posts: { id: ids }) without joinUser.joins(:posts).where(posts: { id: ids })From the same buckets as this rule.
Review SQL/database migrations for operations that can lock large tables or cause downtime. Examples: creating indexes without CONCURRENTLY (Postgres), ALTER COLUMN TYPE on big tables, adding NOT NULL without backfill, long-running updates without batching. Require an online migration strategy (CONCURRENTLY, backfill in batches, dual-write/expand-contract) and a rollback plan.