From c55af9c3b334dd5f81b03805e1e72e0824f8589b Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Sun, 13 Oct 2024 10:31:41 -0400 Subject: [PATCH] update latest note in background (don't await the result) --- packages/backend/src/core/NoteCreateService.ts | 13 ++++++++++--- packages/backend/src/core/NoteDeleteService.ts | 8 +++++++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts index cbc9dcaf8f..55c55589ad 100644 --- a/packages/backend/src/core/NoteCreateService.ts +++ b/packages/backend/src/core/NoteCreateService.ts @@ -531,8 +531,6 @@ export class NoteCreateService implements OnApplicationShutdown { await this.notesRepository.insert(insert); } - await this.updateLatestNote(insert); - return insert; } catch (e) { // duplicate key error @@ -815,6 +813,9 @@ export class NoteCreateService implements OnApplicationShutdown { }); } + // Update the Latest Note index / following feed + this.updateLatestNoteBG(note); + // Register to search database if (!user.noindex) this.index(note); } @@ -1145,7 +1146,13 @@ export class NoteCreateService implements OnApplicationShutdown { this.dispose(); } - private async updateLatestNote(note: MiNote) { + private updateLatestNoteBG(note: MiNote): void { + this + .updateLatestNote(note) + .catch(err => console.error('Unhandled exception while updating latest_note (after create):', err)); + } + + private async updateLatestNote(note: MiNote): Promise { // Ignore DMs. // Followers-only posts are *included*, as this table is used to back the "following" feed. if (note.visibility === 'specified') return; diff --git a/packages/backend/src/core/NoteDeleteService.ts b/packages/backend/src/core/NoteDeleteService.ts index fa77caabd1..3f1eef39c9 100644 --- a/packages/backend/src/core/NoteDeleteService.ts +++ b/packages/backend/src/core/NoteDeleteService.ts @@ -152,7 +152,7 @@ export class NoteDeleteService { userId: user.id, }); - await this.updateLatestNote(note); + this.updateLatestNoteBG(note); if (deleter && (note.userId !== deleter.id)) { const user = await this.usersRepository.findOneByOrFail({ id: note.userId }); @@ -236,6 +236,12 @@ export class NoteDeleteService { } } + private updateLatestNoteBG(note: MiNote): void { + this + .updateLatestNote(note) + .catch(err => console.error('Unhandled exception while updating latest_note (after delete):', err)); + } + private async updateLatestNote(note: MiNote) { // If it's a DM, then it can't possibly be the latest note so we can safely skip this. if (note.visibility === 'specified') return;