mirror of
https://codeberg.org/yeentown/barkey.git
synced 2025-04-28 09:36:56 +00:00
delete fetch logs when a note or user is deleted
This commit is contained in:
parent
dbaeb7f2ac
commit
9de5ecae51
3 changed files with 50 additions and 2 deletions
|
@ -5,7 +5,7 @@
|
|||
|
||||
import { createHash } from 'crypto';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { LessThan } from 'typeorm';
|
||||
import { In, LessThan } from 'typeorm';
|
||||
import { DI } from '@/di-symbols.js';
|
||||
import { SkApFetchLog, SkApInboxLog, SkApContext } from '@/models/_.js';
|
||||
import type { ApContextsRepository, ApFetchLogsRepository, ApInboxLogsRepository } from '@/models/_.js';
|
||||
|
@ -121,6 +121,24 @@ export class ApLogService {
|
|||
.execute();
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all logged copies of an object or objects
|
||||
* @param objectUris URIs / AP IDs of the objects to delete
|
||||
*/
|
||||
public async deleteObjectLogs(objectUris: string | string[]): Promise<number> {
|
||||
if (Array.isArray(objectUris)) {
|
||||
const logsDeleted = await this.apFetchLogsRepository.delete({
|
||||
objectUri: In(objectUris),
|
||||
});
|
||||
return logsDeleted.affected ?? 0;
|
||||
} else {
|
||||
const logsDeleted = await this.apFetchLogsRepository.delete({
|
||||
objectUri: objectUris,
|
||||
});
|
||||
return logsDeleted.affected ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes all expired AP logs and garbage-collects the AP context cache.
|
||||
* Returns the total number of deleted rows.
|
||||
|
|
|
@ -24,9 +24,14 @@ 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';
|
||||
import { ApLogService } from '@/core/ApLogService.js';
|
||||
import Logger from '@/logger.js';
|
||||
import { LoggerService } from './LoggerService.js';
|
||||
|
||||
@Injectable()
|
||||
export class NoteDeleteService {
|
||||
private readonly logger: Logger;
|
||||
|
||||
constructor(
|
||||
@Inject(DI.config)
|
||||
private config: Config,
|
||||
|
@ -55,7 +60,11 @@ export class NoteDeleteService {
|
|||
private perUserNotesChart: PerUserNotesChart,
|
||||
private instanceChart: InstanceChart,
|
||||
private latestNoteService: LatestNoteService,
|
||||
) {}
|
||||
private readonly apLogService: ApLogService,
|
||||
loggerService: LoggerService,
|
||||
) {
|
||||
this.logger = loggerService.getLogger('note-delete-service');
|
||||
}
|
||||
|
||||
/**
|
||||
* 投稿を削除します。
|
||||
|
@ -156,6 +165,11 @@ export class NoteDeleteService {
|
|||
note: note,
|
||||
});
|
||||
}
|
||||
|
||||
if (note.uri) {
|
||||
this.apLogService.deleteObjectLogs(note.uri)
|
||||
.catch(err => this.logger.error(err, `Failed to delete AP logs for note '${note.uri}'`));
|
||||
}
|
||||
}
|
||||
|
||||
@bindThis
|
||||
|
|
|
@ -15,6 +15,7 @@ import type { MiNoteReaction } from '@/models/NoteReaction.js';
|
|||
import { EmailService } from '@/core/EmailService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { SearchService } from '@/core/SearchService.js';
|
||||
import { ApLogService } from '@/core/ApLogService.js';
|
||||
import { ReactionService } from '@/core/ReactionService.js';
|
||||
import { QueueLoggerService } from '../QueueLoggerService.js';
|
||||
import type * as Bull from 'bullmq';
|
||||
|
@ -45,6 +46,7 @@ export class DeleteAccountProcessorService {
|
|||
private queueLoggerService: QueueLoggerService,
|
||||
private searchService: SearchService,
|
||||
private reactionService: ReactionService,
|
||||
private readonly apLogService: ApLogService,
|
||||
) {
|
||||
this.logger = this.queueLoggerService.logger.createSubLogger('delete-account');
|
||||
}
|
||||
|
@ -84,6 +86,13 @@ export class DeleteAccountProcessorService {
|
|||
for (const note of notes) {
|
||||
await this.searchService.unindexNote(note);
|
||||
}
|
||||
|
||||
// Delete note AP logs
|
||||
const noteUris = notes.map(n => n.uri).filter(u => !!u) as string[];
|
||||
if (noteUris.length > 0) {
|
||||
await this.apLogService.deleteObjectLogs(noteUris)
|
||||
.catch(err => this.logger.error(err, `Failed to delete AP logs for notes of user '${user.uri ?? user.id}'`));
|
||||
}
|
||||
}
|
||||
|
||||
this.logger.succ('All of notes deleted');
|
||||
|
@ -149,6 +158,13 @@ export class DeleteAccountProcessorService {
|
|||
this.logger.succ('All of files deleted');
|
||||
}
|
||||
|
||||
{ // Delete actor logs
|
||||
if (user.uri) {
|
||||
await this.apLogService.deleteObjectLogs(user.uri)
|
||||
.catch(err => this.logger.error(err, `Failed to delete AP logs for user '${user.uri}'`));
|
||||
}
|
||||
}
|
||||
|
||||
{ // Send email notification
|
||||
const profile = await this.userProfilesRepository.findOneByOrFail({ userId: user.id });
|
||||
if (profile.email && profile.emailVerified) {
|
||||
|
|
Loading…
Add table
Reference in a new issue