Merge pull request #2530 from basecamp/notification-sorting-optimization

Index notifications on updated_at
This commit is contained in:
Stanko Krtalić
2026-02-12 11:41:36 +01:00
committed by GitHub
3 changed files with 12 additions and 4 deletions
@@ -0,0 +1,8 @@
class FixNotificationsOrderedIndex < ActiveRecord::Migration[8.2]
def change
add_index :notifications, [ :user_id, :read_at, :updated_at ],
order: { read_at: :desc, updated_at: :desc },
name: "index_notifications_on_user_id_and_read_at_and_updated_at"
remove_index :notifications, name: "index_notifications_on_user_id_and_read_at_and_created_at"
end
end
Generated
+2 -2
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.2].define(version: 2026_02_11_122517) do
ActiveRecord::Schema[8.2].define(version: 2026_02_12_102026) do
create_table "accesses", id: :uuid, charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.datetime "accessed_at"
t.uuid "account_id", null: false
@@ -398,7 +398,7 @@ ActiveRecord::Schema[8.2].define(version: 2026_02_11_122517) do
t.index ["creator_id"], name: "index_notifications_on_creator_id"
t.index ["source_type", "source_id"], name: "index_notifications_on_source"
t.index ["user_id", "card_id"], name: "index_notifications_on_user_id_and_card_id", unique: true
t.index ["user_id", "read_at", "created_at"], name: "index_notifications_on_user_id_and_read_at_and_created_at", order: { read_at: :desc, created_at: :desc }
t.index ["user_id", "read_at", "updated_at"], name: "index_notifications_on_user_id_and_read_at_and_updated_at", order: { read_at: :desc, updated_at: :desc }
t.index ["user_id"], name: "index_notifications_on_user_id"
end
+2 -2
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[8.2].define(version: 2026_02_11_122517) do
ActiveRecord::Schema[8.2].define(version: 2026_02_12_102026) do
create_table "accesses", id: :uuid, force: :cascade do |t|
t.datetime "accessed_at"
t.uuid "account_id", null: false
@@ -398,7 +398,7 @@ ActiveRecord::Schema[8.2].define(version: 2026_02_11_122517) do
t.index ["creator_id"], name: "index_notifications_on_creator_id"
t.index ["source_type", "source_id"], name: "index_notifications_on_source"
t.index ["user_id", "card_id"], name: "index_notifications_on_user_id_and_card_id", unique: true
t.index ["user_id", "read_at", "created_at"], name: "index_notifications_on_user_id_and_read_at_and_created_at", order: { read_at: :desc, created_at: :desc }
t.index ["user_id", "read_at", "updated_at"], name: "index_notifications_on_user_id_and_read_at_and_updated_at", order: { read_at: :desc, updated_at: :desc }
t.index ["user_id"], name: "index_notifications_on_user_id"
end