From 384fb76a26834ab34f7f225ce59773332ae12859 Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 15 Dec 2023 23:56:00 +0100 Subject: [PATCH] [backend] Add a new index to the note table for faster generation of following query heuristics --- .../1702680809638-add-note-createdat-userid-idx.ts | 13 +++++++++++++ packages/backend/src/models/entities/note.ts | 1 + 2 files changed, 14 insertions(+) create mode 100644 packages/backend/src/migration/1702680809638-add-note-createdat-userid-idx.ts diff --git a/packages/backend/src/migration/1702680809638-add-note-createdat-userid-idx.ts b/packages/backend/src/migration/1702680809638-add-note-createdat-userid-idx.ts new file mode 100644 index 000000000..e38f9d1a4 --- /dev/null +++ b/packages/backend/src/migration/1702680809638-add-note-createdat-userid-idx.ts @@ -0,0 +1,13 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddNoteCreatedatUseridIdx1702680809638 implements MigrationInterface { + name = 'AddNoteCreatedatUseridIdx1702680809638' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE INDEX IF NOT EXISTS "IDX_note_createdAt_userId" ON "note" ("createdAt", "userId")`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX IF EXISTS "public"."IDX_note_createdAt_userId"`); + } +} diff --git a/packages/backend/src/models/entities/note.ts b/packages/backend/src/models/entities/note.ts index 886e6538f..8062cac51 100644 --- a/packages/backend/src/models/entities/note.ts +++ b/packages/backend/src/models/entities/note.ts @@ -18,6 +18,7 @@ import { Channel } from "./channel.js"; @Index("IDX_NOTE_VISIBLE_USER_IDS", { synchronize: false }) @Index("IDX_note_userId_id", ["userId", "id"]) @Index("IDX_note_id_userHost", ["id", "userHost"]) +@Index("IDX_note_createdAt_userId", ["createdAt", "userId"]) export class Note { @PrimaryColumn(id()) public id: string;