A query returning 100 rows may still scan millions.
In Rails + PostgreSQL, `explain(:analyze, :buffers)` shows actual execution work. A large “Rows Removed by Filter” count can reveal wasted scanning. Use a safe copy of your data: ANALYZE executes the query.
@Espen_Antonsen Agreed on larger exports: background job, https://t.co/XiBPRuxUef(tempfile), then an expiring download link. find_each already batches reads via find_in_batches, but CSV.generate still accumulates the whole file in memory. Batching alone doesn’t fix that.
When a CSV download is slow, the total request time doesn’t tell you how much of it went into building the file.
Wrap generation in ActiveSupport::Notifications.instrument and use monotonic_subscribe to log that phase separately.
If a client sends project as a string, require(:project).permit(…) can turn a bad request into a 500.
In Rails 8+, use params.expect to require a project hash. The client gets a 400 for that payload, so it knows to fix the request instead of retrying.
Here's my rails-performance-inflected takes:
1. Ban cache, cache is cope
2. Ban where/find/exists from instance methods in models/ folder.
3. Ban sleeps in tests
4. All page transitions MUST be Turbo visits or SPA route changes
You must make it impossible to ship slow code
Rails can redact a pickup PIN in the request log and still leak it in your custom JSON log.
Apply ActiveSupport::ParameterFilter with the same filter_parameters before serializing a parsed payload. Use a separate copy for logging.
Delete a cached price before the outer transaction commits and a reader can refill it with the old value.
In Rails 7.2+, use `after_all_transactions_commit` for the cache delete. It waits for the commit even when the caller owns the transaction.
A 422 from checkout can hide an order or payment that was still saved.
RSpec’s define_negated_matcher makes negative change checks composable, so one rejection spec can verify the response and the records it must never create.
A lock_version column alone won’t protect stale Rails edit forms.
If update loads a fresh record, it gets the current version, not the one the user edited. Send the original version in a hidden field and permit it, so Rails can reject a stale submission.