From 6e82e18eea7d34e92b1b205c8a4af2cd575a7ea8 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 22 Nov 2023 04:20:27 +0100 Subject: [PATCH] [backend] Add multi column index for userHost to note table This drastically improves local and social timeline performance --- .../1700623165718-add-note-userhost-id-idx.ts | 13 +++++++++++++ packages/backend/src/models/entities/note.ts | 1 + 2 files changed, 14 insertions(+) create mode 100644 packages/backend/src/migration/1700623165718-add-note-userhost-id-idx.ts diff --git a/packages/backend/src/migration/1700623165718-add-note-userhost-id-idx.ts b/packages/backend/src/migration/1700623165718-add-note-userhost-id-idx.ts new file mode 100644 index 000000000..2ba5759a4 --- /dev/null +++ b/packages/backend/src/migration/1700623165718-add-note-userhost-id-idx.ts @@ -0,0 +1,13 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddNoteIdUserhostIdx1700623165718 implements MigrationInterface { + name = 'AddNoteIdUserhostIdx1700623165718' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE INDEX "IDX_note_id_userHost" ON "note" ("id", "userHost") `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX "public"."IDX_note_id_userHost"`); + } +} diff --git a/packages/backend/src/models/entities/note.ts b/packages/backend/src/models/entities/note.ts index 21a39aa01..4a50c556e 100644 --- a/packages/backend/src/models/entities/note.ts +++ b/packages/backend/src/models/entities/note.ts @@ -17,6 +17,7 @@ import { Channel } from "./channel.js"; @Index("IDX_NOTE_MENTIONS", { synchronize: false }) @Index("IDX_NOTE_VISIBLE_USER_IDS", { synchronize: false }) @Index("IDX_note_userId_id", ["userId", "id"]) +@Index("IDX_note_id_userHost", ["id", "userHost"]) export class Note { @PrimaryColumn(id()) public id: string;