chore: リノートでもなく、リプライでもなく、リプライも自己リノートもないノートについては CleanRemoteNotesProcessor で deleted_note 二追加しないように

This commit is contained in:
anatawa12 2025-08-03 20:52:05 +09:00
parent 019f844e40
commit ce54e810a3
No known key found for this signature in database
GPG Key ID: 9CA909848B8E4EA6
1 changed files with 15 additions and 4 deletions

View File

@ -138,18 +138,29 @@ export class CleanRemoteNotesProcessorService {
const replies = notes.length === 0 ? [] : await this.notesRepository.find({
where: {
replyId: In(notes.map(note => note.id)),
userHost: IsNull(),
},
select: ['replyId'],
select: ['replyId', 'userHost'],
});
const noteIdsWithReplies = new Set(replies.map(reply => reply.replyId));
notes = notes.filter(note => {
return !replies.some(reply => reply.replyId === note.id);
return !replies.some(reply => reply.userHost == null && reply.replyId === note.id);
});
// find self renotes and quotes to determine if we should keep deleted notes
const renotes = notes.length === 0 ? [] : await this.notesRepository.find({
where: {
renoteId: In(notes.map(note => note.id)),
},
select: ['renoteId'],
});
const noteIdsWithRenotes = new Set(renotes.map(reply => reply.replyId));
if (notes.length > 0) {
await this.db.transaction(async (transaction) => {
await transaction.save(MiDeletedNote, notes.map(note => ({
await transaction.save(MiDeletedNote, notes.filter(x => x.replyId != null || x.renoteId != null || noteIdsWithReplies.has(x.id) || noteIdsWithRenotes.has(x.id)).map(note => ({
id: note.id,
deletedAt: null, // This is existing note on the remote, so we set deletedAt to null.
replyId: note.replyId,