summaryrefslogtreecommitdiff
path: root/packages/backend/src/core/NoteDeleteService.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/backend/src/core/NoteDeleteService.ts')
-rw-r--r--packages/backend/src/core/NoteDeleteService.ts62
1 files changed, 6 insertions, 56 deletions
diff --git a/packages/backend/src/core/NoteDeleteService.ts b/packages/backend/src/core/NoteDeleteService.ts
index 6ea400b03e..285db9f152 100644
--- a/packages/backend/src/core/NoteDeleteService.ts
+++ b/packages/backend/src/core/NoteDeleteService.ts
@@ -3,12 +3,11 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
-import { Brackets, In, Not } from 'typeorm';
+import { Brackets, In } from 'typeorm';
import { Injectable, Inject } from '@nestjs/common';
import type { MiUser, MiLocalUser, MiRemoteUser } from '@/models/User.js';
-import type { MiNote, IMentionedRemoteUsers } from '@/models/Note.js';
-import { LatestNote } from '@/models/LatestNote.js';
-import type { InstancesRepository, MiMeta, LatestNotesRepository, NotesRepository, UsersRepository } from '@/models/_.js';
+import { MiNote, IMentionedRemoteUsers } from '@/models/Note.js';
+import type { InstancesRepository, MiMeta, NotesRepository, UsersRepository } from '@/models/_.js';
import { RelayService } from '@/core/RelayService.js';
import { FederatedInstanceService } from '@/core/FederatedInstanceService.js';
import { DI } from '@/di-symbols.js';
@@ -24,6 +23,7 @@ import { bindThis } from '@/decorators.js';
import { SearchService } from '@/core/SearchService.js';
import { ModerationLogService } from '@/core/ModerationLogService.js';
import { isQuote, isRenote } from '@/misc/is-renote.js';
+import { LatestNoteService } from '@/core/LatestNoteService.js';
@Injectable()
export class NoteDeleteService {
@@ -40,9 +40,6 @@ export class NoteDeleteService {
@Inject(DI.notesRepository)
private notesRepository: NotesRepository,
- @Inject(DI.latestNotesRepository)
- private latestNotesRepository: LatestNotesRepository,
-
@Inject(DI.instancesRepository)
private instancesRepository: InstancesRepository,
@@ -57,6 +54,7 @@ export class NoteDeleteService {
private notesChart: NotesChart,
private perUserNotesChart: PerUserNotesChart,
private instanceChart: InstanceChart,
+ private latestNoteService: LatestNoteService,
) {}
/**
@@ -149,7 +147,7 @@ export class NoteDeleteService {
userId: user.id,
});
- await this.updateLatestNote(note);
+ this.latestNoteService.handleDeletedNoteBG(note);
if (deleter && (note.userId !== deleter.id)) {
const user = await this.usersRepository.findOneByOrFail({ id: note.userId });
@@ -232,52 +230,4 @@ export class NoteDeleteService {
this.apDeliverManagerService.deliverToUser(user, content, remoteUser);
}
}
-
- 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;
-
- // Check if the deleted note was possibly the latest for the user
- const hasLatestNote = await this.latestNotesRepository.existsBy({ userId: note.userId });
- if (hasLatestNote) return;
-
- // Find the newest remaining note for the user.
- // We exclude DMs and pure renotes.
- const nextLatest = await this.notesRepository
- .createQueryBuilder('note')
- .select()
- .where({
- userId: note.userId,
- visibility: Not('specified'),
- })
- .andWhere(`
- (
- note."renoteId" IS NULL
- OR note.text IS NOT NULL
- OR note.cw IS NOT NULL
- OR note."replyId" IS NOT NULL
- OR note."hasPoll"
- OR note."fileIds" != '{}'
- )
- `)
- .orderBy({ id: 'DESC' })
- .getOne();
- if (!nextLatest) return;
-
- // Record it as the latest
- const latestNote = new LatestNote({
- userId: note.userId,
- noteId: nextLatest.id,
- });
-
- // When inserting the latest note, it's possible that another worker has "raced" the insert and already added a newer note.
- // We must use orIgnore() to ensure that the query ignores conflicts, otherwise an exception may be thrown.
- await this.latestNotesRepository
- .createQueryBuilder('latest')
- .insert()
- .into(LatestNote)
- .values(latestNote)
- .orIgnore()
- .execute();
- }
}