From 82de8b7c50767e71f5414481fbb4e5ff7a449593 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 21 Mar 2021 22:15:45 +0900 Subject: [PATCH] perf(server): Reduce database query --- src/services/note/create.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/services/note/create.ts b/src/services/note/create.ts index a85e72c5f..96177e975 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -444,8 +444,13 @@ async function renderNoteOrRenoteActivity(data: Option, note: Note) { } function incRenoteCount(renote: Note) { - Notes.increment({ id: renote.id }, 'renoteCount', 1); - Notes.increment({ id: renote.id }, 'score', 1); + Notes.createQueryBuilder().update() + .set({ + renoteCount: () => '"renoteCount" + 1', + score: () => '"score" + 1' + }) + .where('id = :id', { id: renote.id }) + .execute(); } async function insertNote(user: User, data: Option, tags: string[], emojis: string[], mentionedUsers: User[]) { @@ -525,7 +530,7 @@ async function insertNote(user: User, data: Option, tags: string[], emojis: stri await Notes.insert(insert); } - return await Notes.findOneOrFail(insert.id); + return insert; } catch (e) { // duplicate key error if (isDuplicateKeyValueError(e)) {