From 62a7a8a7a3b8ca4d0bf835aed396ca5a80d4b2a0 Mon Sep 17 00:00:00 2001 From: Max Wofford Date: Wed, 7 May 2025 17:20:45 -0400 Subject: [PATCH] Add user+time index to heartbeats --- db/migrate/20250507211848_add_index_to_heartbeats.rb | 7 +++++++ db/schema.rb | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20250507211848_add_index_to_heartbeats.rb diff --git a/db/migrate/20250507211848_add_index_to_heartbeats.rb b/db/migrate/20250507211848_add_index_to_heartbeats.rb new file mode 100644 index 0000000..48410d1 --- /dev/null +++ b/db/migrate/20250507211848_add_index_to_heartbeats.rb @@ -0,0 +1,7 @@ +class AddIndexToHeartbeats < ActiveRecord::Migration[8.0] + def change + add_index :heartbeats, [ :user_id, :time ], + name: "idx_heartbeats_user_time_active", + where: "deleted_at IS NULL" + end +end diff --git a/db/schema.rb b/db/schema.rb index ca5498a..b42a820 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[8.0].define(version: 2025_05_07_204732) do +ActiveRecord::Schema[8.0].define(version: 2025_05_07_211848) do # These are extensions that must be enabled in order to support this database enable_extension "pg_catalog.plpgsql" @@ -210,6 +210,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_05_07_204732) do t.datetime "deleted_at" t.index ["category", "time"], name: "index_heartbeats_on_category_and_time" t.index ["fields_hash"], name: "index_heartbeats_on_fields_hash_when_not_deleted", unique: true, where: "(deleted_at IS NULL)" + t.index ["user_id", "time"], name: "idx_heartbeats_user_time_active", where: "(deleted_at IS NULL)" t.index ["user_id"], name: "index_heartbeats_on_user_id" end