summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/NoteDeleteService.ts
diff options
context:
space:
mode:
authorMar0xy <marie@kaifa.ch>2023-10-21 12:40:08 +0200
committerMar0xy <marie@kaifa.ch>2023-10-21 12:40:08 +0200
commit01a142f777913f311942273527d2f5128a827c39 (patch)
tree236a89c1efe667917a9ecc647361555520822ad7 /packages/backend/src/core/NoteDeleteService.ts
parentupd: change handling of renewkeyFailed (diff)
downloadsharkey-01a142f777913f311942273527d2f5128a827c39.tar.gz
sharkey-01a142f777913f311942273527d2f5128a827c39.tar.bz2
sharkey-01a142f777913f311942273527d2f5128a827c39.zip
fix: increment and decrement of note count
Diffstat (limited to 'packages/backend/src/core/NoteDeleteService.ts')
-rw-r--r--packages/backend/src/core/NoteDeleteService.ts25
1 files changed, 24 insertions, 1 deletions
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);
}
@@ -148,6 +160,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<MiNote[]> {
const recursive = async (noteId: string): Promise<MiNote[]> => {
const query = this.notesRepository.createQueryBuilder('note')