From 01a142f777913f311942273527d2f5128a827c39 Mon Sep 17 00:00:00 2001 From: Mar0xy Date: Sat, 21 Oct 2023 12:40:08 +0200 Subject: fix: increment and decrement of note count --- packages/backend/src/core/NoteDeleteService.ts | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'packages/backend/src/core/NoteDeleteService.ts') diff --git a/packages/backend/src/core/NoteDeleteService.ts b/packages/backend/src/core/NoteDeleteService.ts index 63e49ce0d3..a7944e91ac 100644 --- a/packages/backend/src/core/NoteDeleteService.ts +++ b/packages/backend/src/core/NoteDeleteService.ts @@ -115,9 +115,21 @@ export class NoteDeleteService { this.perUserNotesChart.update(user, note, false); } + if (note.renote && note.text) { + // Decrement notes count (user) + this.decNotesCountOfUser(user); + } else if (!note.renote) { + // Decrement notes count (user) + this.decNotesCountOfUser(user); + } + if (this.userEntityService.isRemoteUser(user)) { this.federatedInstanceService.fetch(user.host).then(async i => { - this.instancesRepository.decrement({ id: i.id }, 'notesCount', 1); + if (note.renote && note.text) { + this.instancesRepository.decrement({ id: i.id }, 'notesCount', 1); + } else if (!note.renote) { + this.instancesRepository.decrement({ id: i.id }, 'notesCount', 1); + } if ((await this.metaService.fetch()).enableChartsForFederatedInstances) { this.instanceChart.updateNote(i.host, note, false); } @@ -147,6 +159,17 @@ export class NoteDeleteService { } } + @bindThis + private decNotesCountOfUser(user: { id: MiUser['id']; }) { + this.usersRepository.createQueryBuilder().update() + .set({ + updatedAt: new Date(), + notesCount: () => '"notesCount" - 1', + }) + .where('id = :id', { id: user.id }) + .execute(); + } + @bindThis private async findCascadingNotes(note: MiNote): Promise { const recursive = async (noteId: string): Promise => { -- cgit v1.2.3-freya