From fb194b855b7548672d95071adfb5f354e78d3f32 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 21 Mar 2021 22:09:32 +0900 Subject: [PATCH] perf(server): Reduce database query --- src/services/note/create.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/services/note/create.ts b/src/services/note/create.ts index 7c7e8d9a0..a85e72c5f 100644 --- a/src/services/note/create.ts +++ b/src/services/note/create.ts @@ -594,10 +594,13 @@ function saveReply(reply: Note, note: Note) { } function incNotesCountOfUser(user: User) { - Users.increment({ id: user.id }, 'notesCount', 1); - Users.update({ id: user.id }, { - updatedAt: new Date() - }); + Users.createQueryBuilder().update() + .set({ + updatedAt: new Date(), + notesCount: () => '"notesCount" + 1' + }) + .where('id = :id', { id: user.id }) + .execute(); } async function extractMentionedUsers(user: User, tokens: ReturnType): Promise {