Add index on readouts(user_id, taken_at)

MeasurementsController#index orders by taken_at desc; without an index
this scan grows linearly with the readout count. The composite index
on (user_id, taken_at) covers both the implicit user_id filter from
the association scope and the ORDER BY clause.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-04 10:20:55 +00:00
parent 3702e24153
commit 862430e586
2 changed files with 2 additions and 0 deletions

View File

@@ -1,5 +1,6 @@
class AddTakenAtToReadouts < ActiveRecord::Migration[7.2]
def change
add_column :readouts, :taken_at, :datetime
add_index :readouts, [:user_id, :taken_at]
end
end