From 2b016d670fdc3542365be1dc87e2128eb8c6cec7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=8A=E3=81=95=E3=82=80=E3=81=AE=E3=81=B2=E3=81=A8?= <46447427+samunohito@users.noreply.github.com> Date: Sat, 30 May 2026 12:35:01 +0900 Subject: [PATCH] feat(backend): add indexes for noteId in note_favorite and user_note_pining tables (#17511) * feat(backend): add indexes for noteId in note_favorite and user_note_pining tables * reformat --- CHANGELOG.md | 1 + ...0059833698-NoteIdIndexForPinAndFavorite.js | 25 +++++++++++++++++++ packages/backend/src/models/NoteFavorite.ts | 1 + packages/backend/src/models/UserNotePining.ts | 1 + 4 files changed, 28 insertions(+) create mode 100644 packages/backend/migration/1780059833698-NoteIdIndexForPinAndFavorite.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 3853b76e4d..db5ed32f2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Server - Enhance: リモートノートクリーニングジョブのスキップ処理のパフォーマンス改善 +- Enhance: リモートノートクリーニングジョブの削除対象検索処理のパフォーマンス改善 - Fix: backend バンドルで `@tensorflow/tfjs-node` を external に含めず、起動時に `@mapbox/node-pre-gyp` の `find()` が backend の package.json を誤検出して `is not node-pre-gyp ready` エラーを永続的に吐く問題を修正 diff --git a/packages/backend/migration/1780059833698-NoteIdIndexForPinAndFavorite.js b/packages/backend/migration/1780059833698-NoteIdIndexForPinAndFavorite.js new file mode 100644 index 0000000000..3a388b1179 --- /dev/null +++ b/packages/backend/migration/1780059833698-NoteIdIndexForPinAndFavorite.js @@ -0,0 +1,25 @@ +/* + * SPDX-FileCopyrightText: syuilo and misskey-project + * SPDX-License-Identifier: AGPL-3.0-only + */ + +const isConcurrentIndexMigrationEnabled = process.env.MISSKEY_MIGRATION_CREATE_INDEX_CONCURRENTLY === '1'; + +export class NoteIdIndexForPinAndFavorite1780059833698 { + name = 'NoteIdIndexForPinAndFavorite1780059833698'; + transaction = isConcurrentIndexMigrationEnabled ? false : undefined; + + async up(queryRunner) { + const concurrently = isConcurrentIndexMigrationEnabled ? 'CONCURRENTLY' : ''; + + await queryRunner.query(`CREATE INDEX ${concurrently} IF NOT EXISTS "IDX_0e00498f180193423c992bc437" ON "note_favorite" ("noteId")`); + await queryRunner.query(`CREATE INDEX ${concurrently} IF NOT EXISTS "IDX_68881008f7c3588ad7ecae471c" ON "user_note_pining" ("noteId")`); + } + + async down(queryRunner) { + const concurrently = isConcurrentIndexMigrationEnabled ? 'CONCURRENTLY' : ''; + + await queryRunner.query(`DROP INDEX ${concurrently} IF EXISTS "public"."IDX_68881008f7c3588ad7ecae471c"`); + await queryRunner.query(`DROP INDEX ${concurrently} IF EXISTS "public"."IDX_0e00498f180193423c992bc437"`); + } +} diff --git a/packages/backend/src/models/NoteFavorite.ts b/packages/backend/src/models/NoteFavorite.ts index 0e498eb70d..51bcb26629 100644 --- a/packages/backend/src/models/NoteFavorite.ts +++ b/packages/backend/src/models/NoteFavorite.ts @@ -24,6 +24,7 @@ export class MiNoteFavorite { @JoinColumn() public user: MiUser | null; + @Index() @Column(id()) public noteId: MiNote['id']; diff --git a/packages/backend/src/models/UserNotePining.ts b/packages/backend/src/models/UserNotePining.ts index 950da2ad22..733d4fb9d8 100644 --- a/packages/backend/src/models/UserNotePining.ts +++ b/packages/backend/src/models/UserNotePining.ts @@ -24,6 +24,7 @@ export class MiUserNotePining { @JoinColumn() public user: MiUser | null; + @Index() @Column(id()) public noteId: MiNote['id'];