From da34acd35fdeca50cba2de809e85de1f22eb5b70 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 21 May 2021 14:13:03 +0900 Subject: [PATCH] Resolve #6563 (#7524) * Resolve #6563 * Update note.ts * Update generate-visibility-query.ts --- migration/1621479946000-add-note-indexes.ts | 16 ++++++++++++++++ src/models/entities/note.ts | 2 ++ .../api/common/generate-visibility-query.ts | 2 +- src/server/api/endpoints/notes/mentions.ts | 4 ++-- 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 migration/1621479946000-add-note-indexes.ts diff --git a/migration/1621479946000-add-note-indexes.ts b/migration/1621479946000-add-note-indexes.ts new file mode 100644 index 0000000000..53d49964a7 --- /dev/null +++ b/migration/1621479946000-add-note-indexes.ts @@ -0,0 +1,16 @@ +import {MigrationInterface, QueryRunner} from "typeorm"; + +export class addNoteIndexes1621479946000 implements MigrationInterface { + name = 'addNoteIndexes1621479946000' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE INDEX "IDX_NOTE_MENTIONS" ON "note" USING gin ("mentions")`, undefined); + await queryRunner.query(`CREATE INDEX "IDX_NOTE_VISIBLE_USER_IDS" ON "note" USING gin ("visibleUserIds")`, undefined); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX "IDX_NOTE_MENTIONS"`, undefined); + await queryRunner.query(`DROP INDEX "IDX_NOTE_VISIBLE_USER_IDS"`, undefined); + } + +} diff --git a/src/models/entities/note.ts b/src/models/entities/note.ts index 2be7d2b33c..9a85532637 100644 --- a/src/models/entities/note.ts +++ b/src/models/entities/note.ts @@ -7,6 +7,8 @@ import { Channel } from './channel'; @Entity() @Index('IDX_NOTE_TAGS', { synchronize: false }) +@Index('IDX_NOTE_MENTIONS', { synchronize: false }) +@Index('IDX_NOTE_VISIBLE_USER_IDS', { synchronize: false }) export class Note { @PrimaryColumn(id()) public id: string; diff --git a/src/server/api/common/generate-visibility-query.ts b/src/server/api/common/generate-visibility-query.ts index 72ed1c46ea..00a50f8211 100644 --- a/src/server/api/common/generate-visibility-query.ts +++ b/src/server/api/common/generate-visibility-query.ts @@ -22,7 +22,7 @@ export function generateVisibilityQuery(q: SelectQueryBuilder, me?: { id: U // または 自分自身 .orWhere('note.userId = :userId1', { userId1: me.id }) // または 自分宛て - .orWhere(':userId2 = ANY(note.visibleUserIds)', { userId2: me.id }) + .orWhere(`'{"${me.id}"}' <@ note.visibleUserIds`) .orWhere(new Brackets(qb => { qb // または フォロワー宛ての投稿であり、 .where('note.visibility = \'followers\'') diff --git a/src/server/api/endpoints/notes/mentions.ts b/src/server/api/endpoints/notes/mentions.ts index 34936c9b54..dddd08eee6 100644 --- a/src/server/api/endpoints/notes/mentions.ts +++ b/src/server/api/endpoints/notes/mentions.ts @@ -60,8 +60,8 @@ export default define(meta, async (ps, user) => { const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId) .andWhere(new Brackets(qb => { qb - .where(`:meId = ANY(note.mentions)`, { meId: user.id }) - .orWhere(`:meId = ANY(note.visibleUserIds)`, { meId: user.id }); + .where(`'{"${user.id}"}' <@ note.mentions`) + .orWhere(`'{"${user.id}"}' <@ note.visibleUserIds`); })) .innerJoinAndSelect('note.user', 'user') .leftJoinAndSelect('note.reply', 'reply')