From 2efdbae42e75992965069f6e7601a724cc5da9a1 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Thu, 28 Sep 2023 02:42:14 +0200 Subject: [PATCH] Add index to improve user/notes endpoint performance --- .../migration/1695861526125-index-note-userid.js | 10 ++++++++++ packages/backend/src/models/entities/note.ts | 1 + 2 files changed, 11 insertions(+) create mode 100644 packages/backend/migration/1695861526125-index-note-userid.js diff --git a/packages/backend/migration/1695861526125-index-note-userid.js b/packages/backend/migration/1695861526125-index-note-userid.js new file mode 100644 index 000000000..7fd991aef --- /dev/null +++ b/packages/backend/migration/1695861526125-index-note-userid.js @@ -0,0 +1,10 @@ +export class IndexNoteUserId1695861526125 { + name = "IndexNoteUserId1695861526125"; + async up(queryRunner) { + await queryRunner.query(`CREATE INDEX "IDX_note_userId_id" ON "note" ("userId", "id")`); + } + + async down(queryRunner) { + await queryRunner.query(`DROP INDEX "IDX_note_userId_id"`); + } +} diff --git a/packages/backend/src/models/entities/note.ts b/packages/backend/src/models/entities/note.ts index edcfdb635..a844da509 100644 --- a/packages/backend/src/models/entities/note.ts +++ b/packages/backend/src/models/entities/note.ts @@ -16,6 +16,7 @@ import { Channel } from "./channel.js"; @Index("IDX_NOTE_TAGS", { synchronize: false }) @Index("IDX_NOTE_MENTIONS", { synchronize: false }) @Index("IDX_NOTE_VISIBLE_USER_IDS", { synchronize: false }) +@Index("IDX_note_userId_id", ["userId", "id"]) export class Note { @PrimaryColumn(id()) public id: string;