Skip to content

Commit

Permalink
Merge pull request #22 from 1673beta/fix-scheduled-note-delete
Browse files Browse the repository at this point in the history
delete scheduled note delete
  • Loading branch information
1673beta authored Mar 14, 2024
2 parents 2d29fa2 + 347afa4 commit e1d97b8
Show file tree
Hide file tree
Showing 16 changed files with 5 additions and 321 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ export class ScheduledDeleteNote1710383352620 {
name = 'ScheduledDeleteNote1710383352620'

async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "notes" ADD "deleteAt" TIMESTAMP WITH TIME ZONE`)
await queryRunner.query(`ALTER TABLE "note" ADD "deleteAt" TIMESTAMP WITH TIME ZONE`)
}

async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "notes" DROP COLUMN "deleteAt"`)
await queryRunner.query(`ALTER TABLE "note" DROP COLUMN "deleteAt"`)
}
}
12 changes: 0 additions & 12 deletions packages/backend/src/core/NoteCreateService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ type Option = {
uri?: string | null;
url?: string | null;
app?: MiApp | null;
deleteAt?: Date | null;
};

@Injectable()
Expand Down Expand Up @@ -413,7 +412,6 @@ export class NoteCreateService implements OnApplicationShutdown {
text: data.text,
hasPoll: data.poll != null,
hasEvent: data.event != null,
deleteAt: data.deleteAt,
cw: data.cw ?? null,
tags: tags.map(tag => normalizeForSearch(tag)),
emojis,
Expand Down Expand Up @@ -584,16 +582,6 @@ export class NoteCreateService implements OnApplicationShutdown {
});
}

if (data.deleteAt) {
const delay = data.deleteAt.getTime() - Date.now();
this.queueService.scheduledNoteDeletionQueue.add(note.id, {
noteId: note.id,
}, {
delay,
removeOnComplete: true,
});
}

if (!silent) {
if (this.userEntityService.isLocalUser(user)) this.activeUsersChart.write(user);

Expand Down
13 changes: 1 addition & 12 deletions packages/backend/src/core/QueueModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { Config } from '@/config.js';
import { QUEUE, baseQueueOptions } from '@/queue/const.js';
import { allSettled } from '@/misc/promise-tracker.js';
import type { Provider } from '@nestjs/common';
import type { DeliverJobData, InboxJobData, EndedPollNotificationJobData, WebhookDeliverJobData, RelationshipJobData, ScheduledNoteDeleteJobData } from '../queue/types.js';
import type { DeliverJobData, InboxJobData, EndedPollNotificationJobData, WebhookDeliverJobData, RelationshipJobData } from '../queue/types.js';

export type SystemQueue = Bull.Queue<Record<string, unknown>>;
export type EndedPollNotificationQueue = Bull.Queue<EndedPollNotificationJobData>;
Expand All @@ -21,7 +21,6 @@ export type DbQueue = Bull.Queue;
export type RelationshipQueue = Bull.Queue<RelationshipJobData>;
export type ObjectStorageQueue = Bull.Queue;
export type WebhookDeliverQueue = Bull.Queue<WebhookDeliverJobData>;
export type ScheduledNoteDeleteJobQueue = Bull.Queue<ScheduledNoteDeleteJobData>;

const $system: Provider = {
provide: 'queue:system',
Expand All @@ -35,12 +34,6 @@ const $endedPollNotification: Provider = {
inject: [DI.config, DI.redisForJobQueue],
};

const $scheduledNoteDelete: Provider = {
provide: 'queue:scheduledNoteDelete',
useFactory: (config: Config, redisForJobQueue: Redis.Redis) => new Bull.Queue(QUEUE.SCHEDULED_NOTE_DELETE, baseQueueOptions(config, QUEUE.SCHEDULED_NOTE_DELETE, redisForJobQueue)),
inject: [DI.config, DI.redisForJobQueue],
};

const $deliver: Provider = {
provide: 'queue:deliver',
useFactory: (config: Config, redisForJobQueue: Redis.Redis) => new Bull.Queue(QUEUE.DELIVER, baseQueueOptions(config, QUEUE.DELIVER, redisForJobQueue)),
Expand Down Expand Up @@ -83,7 +76,6 @@ const $webhookDeliver: Provider = {
providers: [
$system,
$endedPollNotification,
$scheduledNoteDelete,
$deliver,
$inbox,
$db,
Expand All @@ -94,7 +86,6 @@ const $webhookDeliver: Provider = {
exports: [
$system,
$endedPollNotification,
$scheduledNoteDelete,
$deliver,
$inbox,
$db,
Expand All @@ -107,7 +98,6 @@ export class QueueModule implements OnApplicationShutdown {
constructor(
@Inject('queue:system') public systemQueue: SystemQueue,
@Inject('queue:endedPollNotification') public endedPollNotificationQueue: EndedPollNotificationQueue,
@Inject('queue:scheduledNoteDelete') public scheduledNoteDeleteQueue: ScheduledNoteDeleteJobQueue,
@Inject('queue:deliver') public deliverQueue: DeliverQueue,
@Inject('queue:inbox') public inboxQueue: InboxQueue,
@Inject('queue:db') public dbQueue: DbQueue,
Expand All @@ -123,7 +113,6 @@ export class QueueModule implements OnApplicationShutdown {
await Promise.all([
this.systemQueue.close(),
this.endedPollNotificationQueue.close(),
this.scheduledNoteDeleteQueue.close(),
this.deliverQueue.close(),
this.inboxQueue.close(),
this.dbQueue.close(),
Expand Down
3 changes: 1 addition & 2 deletions packages/backend/src/core/QueueService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import type { Antenna } from '@/server/api/endpoints/i/import-antennas.js';
import { ApRequestCreator } from '@/core/activitypub/ApRequestService.js';
import type { DbQueue, DeliverQueue, EndedPollNotificationQueue, InboxQueue, ObjectStorageQueue, RelationshipQueue, SystemQueue, WebhookDeliverQueue, ScheduledNoteDeleteJobQueue } from './QueueModule.js';
import type { DbQueue, DeliverQueue, EndedPollNotificationQueue, InboxQueue, ObjectStorageQueue, RelationshipQueue, SystemQueue, WebhookDeliverQueue } from './QueueModule.js';
import type { DbJobData, DeliverJobData, RelationshipJobData, ThinUser } from '../queue/types.js';
import type httpSignature from '@peertube/http-signature';
import type * as Bull from 'bullmq';
Expand All @@ -27,7 +27,6 @@ export class QueueService {

@Inject('queue:system') public systemQueue: SystemQueue,
@Inject('queue:endedPollNotification') public endedPollNotificationQueue: EndedPollNotificationQueue,
@Inject('queue:scheduledNoteDelete') public scheduledNoteDeleteQueue: ScheduledNoteDeleteJobQueue,
@Inject('queue:deliver') public deliverQueue: DeliverQueue,
@Inject('queue:inbox') public inboxQueue: InboxQueue,
@Inject('queue:db') public dbQueue: DbQueue,
Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/core/entities/NoteEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ export class NoteEntityService implements OnModuleInit {

poll: note.hasPoll ? this.populatePoll(note, meId) : undefined,
event: note.hasEvent ? this.populateEvent(note) : undefined,
deleteAt: note.deleteAt?.toISOString() ?? undefined,

...(meId && Object.keys(note.reactions).length > 0 ? {
myReaction: this.populateMyReaction(note, meId, options?._hint_),
Expand Down
5 changes: 0 additions & 5 deletions packages/backend/src/models/Note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,6 @@ export class MiNote {
})
public hasPoll: boolean;

@Column('timestamp with time zone', {
nullable: true,
})
public deleteAt: Date | null;

@Index()
@Column({
...id(),
Expand Down
5 changes: 0 additions & 5 deletions packages/backend/src/models/json-schema/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,6 @@ export const packedNoteSchema = {
type: 'object',
optional: true, nullable: true,
},
deleteAt: {
type: 'string',
optional: true, nullable: true,
format: 'date-time',
},
channelId: {
type: 'string',
optional: true, nullable: true,
Expand Down
2 changes: 0 additions & 2 deletions packages/backend/src/queue/QueueProcessorModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { CoreModule } from '@/core/CoreModule.js';
import { GlobalModule } from '@/GlobalModule.js';
import { QueueLoggerService } from './QueueLoggerService.js';
import { QueueProcessorService } from './QueueProcessorService.js';
import { ScheduledNoteDeleteProcessorService } from './processors/ScheduledNoteDeleteService.js';
import { DeliverProcessorService } from './processors/DeliverProcessorService.js';
import { EndedPollNotificationProcessorService } from './processors/EndedPollNotificationProcessorService.js';
import { InboxProcessorService } from './processors/InboxProcessorService.js';
Expand Down Expand Up @@ -76,7 +75,6 @@ import { RelationshipProcessorService } from './processors/RelationshipProcessor
ReportAbuseProcessorService,
WebhookDeliverProcessorService,
EndedPollNotificationProcessorService,
ScheduledNoteDeleteProcessorService,
DeliverProcessorService,
InboxProcessorService,
AggregateRetentionProcessorService,
Expand Down
12 changes: 0 additions & 12 deletions packages/backend/src/queue/QueueProcessorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import type Logger from '@/logger.js';
import { bindThis } from '@/decorators.js';
import { WebhookDeliverProcessorService } from './processors/WebhookDeliverProcessorService.js';
import { EndedPollNotificationProcessorService } from './processors/EndedPollNotificationProcessorService.js';
import { ScheduledNoteDeleteProcessorService } from './processors/ScheduledNoteDeleteService.js';
import { DeliverProcessorService } from './processors/DeliverProcessorService.js';
import { InboxProcessorService } from './processors/InboxProcessorService.js';
import { DeleteDriveFilesProcessorService } from './processors/DeleteDriveFilesProcessorService.js';
Expand Down Expand Up @@ -76,7 +75,6 @@ export class QueueProcessorService implements OnApplicationShutdown {
private logger: Logger;
private systemQueueWorker: Bull.Worker;
private dbQueueWorker: Bull.Worker;
private scheduleNoteDeleteQueueWorker: Bull.Worker;
private deliverQueueWorker: Bull.Worker;
private inboxQueueWorker: Bull.Worker;
private webhookDeliverQueueWorker: Bull.Worker;
Expand Down Expand Up @@ -123,7 +121,6 @@ export class QueueProcessorService implements OnApplicationShutdown {
private aggregateRetentionProcessorService: AggregateRetentionProcessorService,
private checkExpiredMutingsProcessorService: CheckExpiredMutingsProcessorService,
private cleanProcessorService: CleanProcessorService,
private scheduledNoteDeleteProcessorService: ScheduledNoteDeleteProcessorService,
) {
this.logger = this.queueLoggerService.logger;

Expand Down Expand Up @@ -339,13 +336,6 @@ export class QueueProcessorService implements OnApplicationShutdown {
autorun: false,
});
//#endregion

//#region scheduled note delete
this.scheduledNoteDeleteProcessorService = new Bull.Worker(QUEUE.SCHEDULED_NOTE_DELETE, (job) => this.scheduledNoteDeleteProcessorService.process(job), {
...baseQueueOptions(this.config, QUEUE.SCHEDULED_NOTE_DELETE),
autorun: false,
});
//#endregion
}

@bindThis
Expand All @@ -359,7 +349,6 @@ export class QueueProcessorService implements OnApplicationShutdown {
this.relationshipQueueWorker.run(),
this.objectStorageQueueWorker.run(),
this.endedPollNotificationQueueWorker.run(),
this.scheduleNoteDeleteQueueWorker.run(),
]);
}

Expand All @@ -374,7 +363,6 @@ export class QueueProcessorService implements OnApplicationShutdown {
this.relationshipQueueWorker.close(),
this.objectStorageQueueWorker.close(),
this.endedPollNotificationQueueWorker.close(),
this.scheduleNoteDeleteQueueWorker.close(),
]);
}

Expand Down
1 change: 0 additions & 1 deletion packages/backend/src/queue/const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const QUEUE = {
INBOX: 'inbox',
SYSTEM: 'system',
ENDED_POLL_NOTIFICATION: 'endedPollNotification',
SCHEDULED_NOTE_DELETE: 'scheduledNoteDelete',
DB: 'db',
RELATIONSHIP: 'relationship',
OBJECT_STORAGE: 'objectStorage',
Expand Down

This file was deleted.

4 changes: 0 additions & 4 deletions packages/backend/src/queue/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ export type EndedPollNotificationJobData = {
noteId: MiNote['id'];
};

export type ScheduledNoteDeleteJobData = {
noteId: MiNote['id'];
};

export type WebhookDeliverJobData = {
type: string;
content: unknown;
Expand Down
19 changes: 0 additions & 19 deletions packages/backend/src/server/api/endpoints/notes/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,6 @@ export const paramDef = {
metadata: { type: 'object' },
},
},
scheduledDelete: {
type: 'object',
nullable: true,
properties: {
deleteAt: { type: 'integer', nullable: true },
deleteAfter: { type: 'integer', nullable: true, minimum: 1 },
},
},
},
// (re)note with text, files and poll are optional
if: {
Expand Down Expand Up @@ -357,16 +349,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
}
}

if (ps.scheduledDelete) {
if (typeof ps.scheduledDelete.deleteAt === 'number') {
if (ps.scheduledDelete.deleteAt < Date.now()) {
throw new ApiError(meta.errors.cannotScheduleDeleteEarlierThanNow);
}
} else if (typeof ps.scheduledDelete.deleteAfter === 'number') {
ps.scheduledDelete.deleteAt = Date.now() + ps.scheduledDelete.deleteAfter;
}
}

let channel: MiChannel | null = null;
if (ps.channelId != null) {
channel = await this.channelsRepository.findOneBy({ id: ps.channelId, isArchived: false });
Expand Down Expand Up @@ -405,7 +387,6 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
apMentions: ps.noExtractMentions ? [] : undefined,
apHashtags: ps.noExtractHashtags ? [] : undefined,
apEmojis: ps.noExtractEmojis ? [] : undefined,
deleteAt: ps.scheduledDelete?.deleteAt ? new Date(ps.scheduledDelete.deleteAt) : null,
});

return {
Expand Down
4 changes: 1 addition & 3 deletions packages/backend/src/server/web/ClientServerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { getNoteSummary } from '@/misc/get-note-summary.js';
import { DI } from '@/di-symbols.js';
import * as Acct from '@/misc/acct.js';
import { MetaService } from '@/core/MetaService.js';
import type { DbQueue, DeliverQueue, EndedPollNotificationQueue, InboxQueue, ObjectStorageQueue, SystemQueue, WebhookDeliverQueue, ScheduledNoteDeleteJobQueue } from '@/core/QueueModule.js';
import type { DbQueue, DeliverQueue, EndedPollNotificationQueue, InboxQueue, ObjectStorageQueue, SystemQueue, WebhookDeliverQueue } from '@/core/QueueModule.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { NoteEntityService } from '@/core/entities/NoteEntityService.js';
import { PageEntityService } from '@/core/entities/PageEntityService.js';
Expand Down Expand Up @@ -105,7 +105,6 @@ export class ClientServerService {

@Inject('queue:system') public systemQueue: SystemQueue,
@Inject('queue:endedPollNotification') public endedPollNotificationQueue: EndedPollNotificationQueue,
@Inject('queue:scheduledNoteDelete') public scheduledNoteDeleteQueue: ScheduledNoteDeleteJobQueue,
@Inject('queue:deliver') public deliverQueue: DeliverQueue,
@Inject('queue:inbox') public inboxQueue: InboxQueue,
@Inject('queue:db') public dbQueue: DbQueue,
Expand Down Expand Up @@ -223,7 +222,6 @@ export class ClientServerService {
queues: [
this.systemQueue,
this.endedPollNotificationQueue,
this.scheduledNoteDeleteQueue,
this.deliverQueue,
this.inboxQueue,
this.dbQueue,
Expand Down
Loading

0 comments on commit e1d97b8

Please sign in to comment.