From cc2edae7abff566ba968a6027018826099400320 Mon Sep 17 00:00:00 2001 From: Hazelnoot Date: Mon, 9 Dec 2024 10:00:25 -0500 Subject: rename activity_log and activity_context to ap_inbox_log and ap_context --- ...56280460-rename_activity_log_to_ap_inbox_log.js | 32 ++++++ packages/backend/src/boot/common.ts | 4 +- .../src/daemons/ActivityLogCleanupService.ts | 73 -------------- .../backend/src/daemons/ApLogCleanupService.ts | 73 ++++++++++++++ packages/backend/src/daemons/DaemonModule.ts | 6 +- packages/backend/src/di-symbols.ts | 5 +- packages/backend/src/models/RepositoryModule.ts | 24 ++--- packages/backend/src/models/SkActivityContext.ts | 25 ----- packages/backend/src/models/SkActivityLog.ts | 92 ----------------- packages/backend/src/models/SkApContext.ts | 25 +++++ packages/backend/src/models/SkApInboxLog.ts | 109 +++++++++++++++++++++ packages/backend/src/models/_.ts | 12 +-- packages/backend/src/postgres.ts | 8 +- .../src/queue/processors/InboxProcessorService.ts | 30 +++--- 14 files changed, 283 insertions(+), 235 deletions(-) create mode 100644 packages/backend/migration/1733756280460-rename_activity_log_to_ap_inbox_log.js delete mode 100644 packages/backend/src/daemons/ActivityLogCleanupService.ts create mode 100644 packages/backend/src/daemons/ApLogCleanupService.ts delete mode 100644 packages/backend/src/models/SkActivityContext.ts delete mode 100644 packages/backend/src/models/SkActivityLog.ts create mode 100644 packages/backend/src/models/SkApContext.ts create mode 100644 packages/backend/src/models/SkApInboxLog.ts diff --git a/packages/backend/migration/1733756280460-rename_activity_log_to_ap_inbox_log.js b/packages/backend/migration/1733756280460-rename_activity_log_to_ap_inbox_log.js new file mode 100644 index 0000000000..ad25135188 --- /dev/null +++ b/packages/backend/migration/1733756280460-rename_activity_log_to_ap_inbox_log.js @@ -0,0 +1,32 @@ +/* + * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +export class RenameActivityLogToApInboxLog1733756280460 { + name = 'RenameActivityLogToApInboxLog1733756280460' + + async up(queryRunner) { + await queryRunner.query(`ALTER INDEX "IDX_activity_log_at" RENAME TO "IDX_ap_inbox_log_at"`); + await queryRunner.query(`ALTER INDEX "IDX_activity_log_host" RENAME TO "IDX_ap_inbox_log_host"`); + await queryRunner.query(`ALTER TABLE "activity_log" RENAME CONSTRAINT "PK_activity_log" TO "PK_ap_inbox_log"`); + await queryRunner.query(`ALTER TABLE "activity_log" RENAME CONSTRAINT "FK_activity_log_context_hash" TO "FK_ap_inbox_log_context_hash"`); + await queryRunner.query(`ALTER TABLE "activity_log" RENAME CONSTRAINT "FK_activity_log_auth_user_id" TO "FK_ap_inbox_log_auth_user_id"`); + await queryRunner.query(`ALTER TABLE "activity_log" RENAME TO "ap_inbox_log"`); + + await queryRunner.query(`ALTER TABLE "activity_context" RENAME CONSTRAINT "PK_activity_context" TO "PK_ap_context"`); + await queryRunner.query(`ALTER TABLE "activity_context" RENAME TO "ap_context"`); + } + + async down(queryRunner) { + await queryRunner.query(`ALTER TABLE "ap_context" RENAME TO "activity_context"`); + await queryRunner.query(`ALTER TABLE "activity_context" RENAME CONSTRAINT "PK_ap_context" TO "PK_activity_context"`); + + await queryRunner.query(`ALTER TABLE "ap_inbox_log" RENAME TO "activity_log"`); + await queryRunner.query(`ALTER TABLE "activity_log" RENAME CONSTRAINT "FK_ap_inbox_log_auth_user_id" TO "FK_activity_log_auth_user_id"`); + await queryRunner.query(`ALTER TABLE "activity_log" RENAME CONSTRAINT "FK_ap_inbox_log_context_hash" TO "FK_activity_log_context_hash"`); + await queryRunner.query(`ALTER TABLE "activity_log" RENAME CONSTRAINT "PK_ap_inbox_log" TO "PK_activity_log"`); + await queryRunner.query(`ALTER INDEX "IDX_ap_inbox_log_host" RENAME TO "IDX_activity_log_host"`); + await queryRunner.query(`ALTER INDEX "IDX_ap_inbox_log_at" RENAME TO "IDX_activity_log_at"`); + } +} diff --git a/packages/backend/src/boot/common.ts b/packages/backend/src/boot/common.ts index 3584e71153..2f97980e9a 100644 --- a/packages/backend/src/boot/common.ts +++ b/packages/backend/src/boot/common.ts @@ -13,7 +13,7 @@ import { ServerStatsService } from '@/daemons/ServerStatsService.js'; import { ServerService } from '@/server/ServerService.js'; import { MainModule } from '@/MainModule.js'; import { envOption } from '@/env.js'; -import { ActivityLogCleanupService } from '@/daemons/ActivityLogCleanupService.js'; +import { ApLogCleanupService } from '@/daemons/ApLogCleanupService.js'; export async function server() { const app = await NestFactory.createApplicationContext(MainModule, { @@ -29,7 +29,7 @@ export async function server() { if (!envOption.noDaemons) { app.get(QueueStatsService).start(); app.get(ServerStatsService).start(); - app.get(ActivityLogCleanupService).start(); + app.get(ApLogCleanupService).start(); } return app; diff --git a/packages/backend/src/daemons/ActivityLogCleanupService.ts b/packages/backend/src/daemons/ActivityLogCleanupService.ts deleted file mode 100644 index bf5ddec05d..0000000000 --- a/packages/backend/src/daemons/ActivityLogCleanupService.ts +++ /dev/null @@ -1,73 +0,0 @@ -/* - * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors - * SPDX-License-Identifier: AGPL-3.0-only - */ - -import { Inject, Injectable, type OnApplicationShutdown } from '@nestjs/common'; -import { LessThan } from 'typeorm'; -import { DI } from '@/di-symbols.js'; -import type { Config } from '@/config.js'; -import { bindThis } from '@/decorators.js'; -import type { ActivityLogsRepository } from '@/models/_.js'; -import { LoggerService } from '@/core/LoggerService.js'; -import Logger from '@/logger.js'; - -// 10 minutes -export const scanInterval = 1000 * 60 * 10; - -@Injectable() -export class ActivityLogCleanupService implements OnApplicationShutdown { - private readonly logger: Logger; - private scanTimer: NodeJS.Timeout | null = null; - - constructor( - @Inject(DI.config) - private readonly config: Config, - - @Inject(DI.activityLogsRepository) - private readonly activityLogsRepository: ActivityLogsRepository, - - loggerService: LoggerService, - ) { - this.logger = loggerService.getLogger('activity-log-cleanup'); - } - - @bindThis - public async start(): Promise { - // Just in case start() gets called multiple times. - this.dispose(); - - // Prune at startup, in case the server was rebooted during the interval. - // noinspection ES6MissingAwait - this.tick(); - - // Prune on a regular interval for the lifetime of the server. - this.scanTimer = setInterval(this.tick, scanInterval); - } - - @bindThis - private async tick(): Promise { - // This is the date in UTC of the oldest log to KEEP - const oldestAllowed = new Date(Date.now() - this.config.activityLogging.maxAge); - - // Delete all logs older than the threshold. - const { affected } = await this.activityLogsRepository.delete({ - at: LessThan(oldestAllowed), - }); - - this.logger.info(`Activity Log cleanup complete; removed ${affected ?? 0} expired logs.`); - } - - @bindThis - public onApplicationShutdown(): void { - this.dispose(); - } - - @bindThis - public dispose(): void { - if (this.scanTimer) { - clearInterval(this.scanTimer); - this.scanTimer = null; - } - } -} diff --git a/packages/backend/src/daemons/ApLogCleanupService.ts b/packages/backend/src/daemons/ApLogCleanupService.ts new file mode 100644 index 0000000000..261c6e3517 --- /dev/null +++ b/packages/backend/src/daemons/ApLogCleanupService.ts @@ -0,0 +1,73 @@ +/* + * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { Inject, Injectable, type OnApplicationShutdown } from '@nestjs/common'; +import { LessThan } from 'typeorm'; +import { DI } from '@/di-symbols.js'; +import type { Config } from '@/config.js'; +import { bindThis } from '@/decorators.js'; +import type { ApInboxLogsRepository } from '@/models/_.js'; +import { LoggerService } from '@/core/LoggerService.js'; +import Logger from '@/logger.js'; + +// 10 minutes +export const scanInterval = 1000 * 60 * 10; + +@Injectable() +export class ApLogCleanupService implements OnApplicationShutdown { + private readonly logger: Logger; + private scanTimer: NodeJS.Timeout | null = null; + + constructor( + @Inject(DI.config) + private readonly config: Config, + + @Inject(DI.apInboxLogsRepository) + private readonly apInboxLogsRepository: ApInboxLogsRepository, + + loggerService: LoggerService, + ) { + this.logger = loggerService.getLogger('activity-log-cleanup'); + } + + @bindThis + public async start(): Promise { + // Just in case start() gets called multiple times. + this.dispose(); + + // Prune at startup, in case the server was rebooted during the interval. + // noinspection ES6MissingAwait + this.tick(); + + // Prune on a regular interval for the lifetime of the server. + this.scanTimer = setInterval(this.tick, scanInterval); + } + + @bindThis + private async tick(): Promise { + // This is the date in UTC of the oldest log to KEEP + const oldestAllowed = new Date(Date.now() - this.config.activityLogging.maxAge); + + // Delete all logs older than the threshold. + const { affected } = await this.apInboxLogsRepository.delete({ + at: LessThan(oldestAllowed), + }); + + this.logger.info(`Activity Log cleanup complete; removed ${affected ?? 0} expired logs.`); + } + + @bindThis + public onApplicationShutdown(): void { + this.dispose(); + } + + @bindThis + public dispose(): void { + if (this.scanTimer) { + clearInterval(this.scanTimer); + this.scanTimer = null; + } + } +} diff --git a/packages/backend/src/daemons/DaemonModule.ts b/packages/backend/src/daemons/DaemonModule.ts index 12f890b3eb..ea71875f19 100644 --- a/packages/backend/src/daemons/DaemonModule.ts +++ b/packages/backend/src/daemons/DaemonModule.ts @@ -8,7 +8,7 @@ import { CoreModule } from '@/core/CoreModule.js'; import { GlobalModule } from '@/GlobalModule.js'; import { QueueStatsService } from './QueueStatsService.js'; import { ServerStatsService } from './ServerStatsService.js'; -import { ActivityLogCleanupService } from './ActivityLogCleanupService.js'; +import { ApLogCleanupService } from './ApLogCleanupService.js'; @Module({ imports: [ @@ -18,12 +18,12 @@ import { ActivityLogCleanupService } from './ActivityLogCleanupService.js'; providers: [ QueueStatsService, ServerStatsService, - ActivityLogCleanupService, + ApLogCleanupService, ], exports: [ QueueStatsService, ServerStatsService, - ActivityLogCleanupService, + ApLogCleanupService, ], }) export class DaemonModule {} diff --git a/packages/backend/src/di-symbols.ts b/packages/backend/src/di-symbols.ts index e591024fbd..6b53d38fb7 100644 --- a/packages/backend/src/di-symbols.ts +++ b/packages/backend/src/di-symbols.ts @@ -22,9 +22,8 @@ export const DI = { appsRepository: Symbol('appsRepository'), avatarDecorationsRepository: Symbol('avatarDecorationsRepository'), latestNotesRepository: Symbol('latestNotesRepository'), - activityContextRepository: Symbol('activityContextRepository'), - contextUsagesRepository: Symbol('contextUsagesRepository'), - activityLogsRepository: Symbol('activityLogsRepository'), + apContextsRepository: Symbol('apContextsRepository'), + apInboxLogsRepository: Symbol('apInboxLogsRepository'), noteFavoritesRepository: Symbol('noteFavoritesRepository'), noteThreadMutingsRepository: Symbol('noteThreadMutingsRepository'), noteReactionsRepository: Symbol('noteReactionsRepository'), diff --git a/packages/backend/src/models/RepositoryModule.ts b/packages/backend/src/models/RepositoryModule.ts index 37c4e4fd92..dd4ba1c0e4 100644 --- a/packages/backend/src/models/RepositoryModule.ts +++ b/packages/backend/src/models/RepositoryModule.ts @@ -81,8 +81,8 @@ import { MiUserSecurityKey, MiWebhook, NoteEdit, - SkActivityContext, - SkActivityLog, + SkApContext, + SkApInboxLog, } from './_.js'; import type { DataSource } from 'typeorm'; @@ -128,15 +128,15 @@ const $latestNotesRepository: Provider = { inject: [DI.db], }; -const $activityContextRepository: Provider = { - provide: DI.activityContextRepository, - useFactory: (db: DataSource) => db.getRepository(SkActivityContext).extend(miRepository as MiRepository), +const $apContextRepository: Provider = { + provide: DI.apContextsRepository, + useFactory: (db: DataSource) => db.getRepository(SkApContext).extend(miRepository as MiRepository), inject: [DI.db], }; -const $activityLogsRepository: Provider = { - provide: DI.activityLogsRepository, - useFactory: (db: DataSource) => db.getRepository(SkActivityLog).extend(miRepository as MiRepository), +const $apInboxLogsRepository: Provider = { + provide: DI.apInboxLogsRepository, + useFactory: (db: DataSource) => db.getRepository(SkApInboxLog).extend(miRepository as MiRepository), inject: [DI.db], }; @@ -540,8 +540,8 @@ const $noteScheduleRepository: Provider = { $appsRepository, $avatarDecorationsRepository, $latestNotesRepository, - $activityContextRepository, - $activityLogsRepository, + $apContextRepository, + $apInboxLogsRepository, $noteFavoritesRepository, $noteThreadMutingsRepository, $noteReactionsRepository, @@ -616,8 +616,8 @@ const $noteScheduleRepository: Provider = { $appsRepository, $avatarDecorationsRepository, $latestNotesRepository, - $activityContextRepository, - $activityLogsRepository, + $apContextRepository, + $apInboxLogsRepository, $noteFavoritesRepository, $noteThreadMutingsRepository, $noteReactionsRepository, diff --git a/packages/backend/src/models/SkActivityContext.ts b/packages/backend/src/models/SkActivityContext.ts deleted file mode 100644 index 349c3e7113..0000000000 --- a/packages/backend/src/models/SkActivityContext.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors - * SPDX-License-Identifier: AGPL-3.0-only - */ - -import { Column, PrimaryColumn, Entity } from 'typeorm'; - -@Entity('activity_context') -export class SkActivityContext { - @PrimaryColumn('text', { - primaryKeyConstraintName: 'PK_activity_context', - }) - public md5: string; - - @Column('jsonb') - // https://github.com/typeorm/typeorm/issues/8559 - // eslint-disable-next-line @typescript-eslint/no-explicit-any - public json: any; - - constructor(data?: Partial) { - if (data) { - Object.assign(this, data); - } - } -} diff --git a/packages/backend/src/models/SkActivityLog.ts b/packages/backend/src/models/SkActivityLog.ts deleted file mode 100644 index 6e462eccef..0000000000 --- a/packages/backend/src/models/SkActivityLog.ts +++ /dev/null @@ -1,92 +0,0 @@ -/* - * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors - * SPDX-License-Identifier: AGPL-3.0-only - */ - -import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm'; -import { SkActivityContext } from '@/models/SkActivityContext.js'; -import { MiUser } from '@/models/_.js'; -import { id } from './util/id.js'; - -@Entity('activity_log') -export class SkActivityLog { - @PrimaryColumn({ - ...id(), - primaryKeyConstraintName: 'PK_activity_log', - }) - public id: string; - - @Index('IDX_activity_log_at') - @Column('timestamptz') - public at: Date; - - /** - * Processing duration in milliseconds - */ - @Column('double precision', { nullable: true }) - public duration: number | null = null; - - @Column({ - type: 'text', - name: 'key_id', - }) - public keyId: string; - - @Index('IDX_activity_log_host') - @Column('text') - public host: string; - - @Column('boolean') - public verified: boolean; - - @Column('boolean') - public accepted: boolean; - - @Column('text', { nullable: true }) - public result: string | null = null; - - @Column('jsonb') - // https://github.com/typeorm/typeorm/issues/8559 - // eslint-disable-next-line @typescript-eslint/no-explicit-any - public activity: any; - - @Column({ - type: 'text', - name: 'context_hash', - nullable: true, - }) - public contextHash: string | null; - - @ManyToOne(() => SkActivityContext, { - onDelete: 'CASCADE', - nullable: true, - }) - @JoinColumn({ - name: 'context_hash', - foreignKeyConstraintName: 'FK_activity_log_context_hash', - }) - public context: SkActivityContext | null; - - @Column({ - ...id(), - name: 'auth_user_id', - nullable: true, - }) - public authUserId: string | null; - - @ManyToOne(() => MiUser, { - onDelete: 'CASCADE', - nullable: true, - }) - @JoinColumn({ - name: 'auth_user_id', - foreignKeyConstraintName: 'FK_activity_log_auth_user_id', - }) - public authUser: MiUser | null; - - constructor(data?: Partial) { - if (data) { - Object.assign(this, data); - } - } -} diff --git a/packages/backend/src/models/SkApContext.ts b/packages/backend/src/models/SkApContext.ts new file mode 100644 index 0000000000..ff4c6d6fbf --- /dev/null +++ b/packages/backend/src/models/SkApContext.ts @@ -0,0 +1,25 @@ +/* + * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { Column, PrimaryColumn, Entity } from 'typeorm'; + +@Entity('ap_context') +export class SkApContext { + @PrimaryColumn('text', { + primaryKeyConstraintName: 'PK_ap_context', + }) + public md5: string; + + @Column('jsonb') + // https://github.com/typeorm/typeorm/issues/8559 + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public json: any; + + constructor(data?: Partial) { + if (data) { + Object.assign(this, data); + } + } +} diff --git a/packages/backend/src/models/SkApInboxLog.ts b/packages/backend/src/models/SkApInboxLog.ts new file mode 100644 index 0000000000..867094405c --- /dev/null +++ b/packages/backend/src/models/SkApInboxLog.ts @@ -0,0 +1,109 @@ +/* + * SPDX-FileCopyrightText: hazelnoot and other Sharkey contributors + * SPDX-License-Identifier: AGPL-3.0-only + */ + +import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm'; +import { SkApContext } from '@/models/SkApContext.js'; +import { MiUser } from '@/models/_.js'; +import { id } from './util/id.js'; + +/** + * Records activities received in the inbox + */ +@Entity('ap_inbox_log') +export class SkApInboxLog { + @PrimaryColumn({ + ...id(), + primaryKeyConstraintName: 'PK_ap_inbox_log', + }) + public id: string; + + @Index('IDX_ap_inbox_log_at') + @Column('timestamptz') + public at: Date; + + /** + * Processing duration in milliseconds + */ + @Column('double precision', { nullable: true }) + public duration: number | null = null; + + /** + * Key ID that was used to sign this request. + * Untrusted unless verified is true. + */ + @Column({ + type: 'text', + name: 'key_id', + }) + public keyId: string; + + /** + * Instance that the activity was sent from. + * Untrusted unless verified is true. + */ + @Index('IDX_ap_inbox_log_host') + @Column('text') + public host: string; + + @Column('boolean') + public verified: boolean; + + @Column('boolean') + public accepted: boolean; + + @Column('text', { nullable: true }) + public result: string | null = null; + + @Column('jsonb') + // https://github.com/typeorm/typeorm/issues/8559 + // eslint-disable-next-line @typescript-eslint/no-explicit-any + public activity: any; + + @Column({ + type: 'text', + name: 'context_hash', + nullable: true, + }) + public contextHash: string | null; + + @ManyToOne(() => SkApContext, { + onDelete: 'CASCADE', + nullable: true, + }) + @JoinColumn({ + name: 'context_hash', + foreignKeyConstraintName: 'FK_ap_inbox_log_context_hash', + }) + public context: SkApContext | null; + + /** + * ID of the user who signed this request. + */ + @Column({ + ...id(), + name: 'auth_user_id', + nullable: true, + }) + public authUserId: string | null; + + /** + * User who signed this request. + */ + @ManyToOne(() => MiUser, { + onDelete: 'CASCADE', + nullable: true, + }) + @JoinColumn({ + name: 'auth_user_id', + foreignKeyConstraintName: 'FK_ap_inbox_log_auth_user_id', + }) + public authUser: MiUser | null; + + constructor(data?: Partial) { + if (data) { + Object.assign(this, data); + } + } +} diff --git a/packages/backend/src/models/_.ts b/packages/backend/src/models/_.ts index aeb6133d70..dabcf89d2c 100644 --- a/packages/backend/src/models/_.ts +++ b/packages/backend/src/models/_.ts @@ -82,8 +82,8 @@ import { NoteEdit } from '@/models/NoteEdit.js'; import { MiBubbleGameRecord } from '@/models/BubbleGameRecord.js'; import { MiReversiGame } from '@/models/ReversiGame.js'; import { MiNoteSchedule } from '@/models/NoteSchedule.js'; -import { SkActivityLog } from '@/models/SkActivityLog.js'; -import { SkActivityContext } from './SkActivityContext.js'; +import { SkApInboxLog } from '@/models/SkApInboxLog.js'; +import { SkApContext } from '@/models/SkApContext.js'; import type { QueryDeepPartialEntity } from 'typeorm/query-builder/QueryPartialEntity.js'; export interface MiRepository { @@ -131,8 +131,8 @@ export const miRepository = { export { SkLatestNote, - SkActivityContext, - SkActivityLog, + SkApContext, + SkApInboxLog, MiAbuseUserReport, MiAbuseReportNotificationRecipient, MiAccessToken, @@ -233,8 +233,8 @@ export type HashtagsRepository = Repository & MiRepository export type InstancesRepository = Repository & MiRepository; export type MetasRepository = Repository & MiRepository; export type LatestNotesRepository = Repository & MiRepository; -export type ActivityContextRepository = Repository & MiRepository; -export type ActivityLogsRepository = Repository & MiRepository; +export type ApContextsRepository = Repository & MiRepository; +export type ApInboxLogsRepository = Repository & MiRepository; export type ModerationLogsRepository = Repository & MiRepository; export type MutingsRepository = Repository & MiRepository; export type RenoteMutingsRepository = Repository & MiRepository; diff --git a/packages/backend/src/postgres.ts b/packages/backend/src/postgres.ts index 658830ffcb..9437ac936a 100644 --- a/packages/backend/src/postgres.ts +++ b/packages/backend/src/postgres.ts @@ -85,8 +85,8 @@ import { Config } from '@/config.js'; import MisskeyLogger from '@/logger.js'; import { bindThis } from '@/decorators.js'; import { SkLatestNote } from '@/models/LatestNote.js'; -import { SkActivityContext } from '@/models/SkActivityContext.js'; -import { SkActivityLog } from '@/models/SkActivityLog.js'; +import { SkApContext } from '@/models/SkApContext.js'; +import { SkApInboxLog } from '@/models/SkApInboxLog.js'; pg.types.setTypeParser(20, Number); @@ -173,8 +173,8 @@ class MyCustomLogger implements Logger { export const entities = [ SkLatestNote, - SkActivityContext, - SkActivityLog, + SkApContext, + SkApInboxLog, MiAnnouncement, MiAnnouncementRead, MiMeta, diff --git a/packages/backend/src/queue/processors/InboxProcessorService.ts b/packages/backend/src/queue/processors/InboxProcessorService.ts index 5ed124a049..4182f3e090 100644 --- a/packages/backend/src/queue/processors/InboxProcessorService.ts +++ b/packages/backend/src/queue/processors/InboxProcessorService.ts @@ -32,8 +32,8 @@ import { MiMeta } from '@/models/Meta.js'; import { DI } from '@/di-symbols.js'; import { IdService } from '@/core/IdService.js'; import { JsonValue } from '@/misc/json-value.js'; -import { SkActivityLog, SkActivityContext } from '@/models/_.js'; -import type { ActivityLogsRepository, ActivityContextRepository } from '@/models/_.js'; +import { SkApInboxLog, SkApContext } from '@/models/_.js'; +import type { ApInboxLogsRepository, ApContextsRepository } from '@/models/_.js'; import type { Config } from '@/config.js'; import { QueueLoggerService } from '../QueueLoggerService.js'; import type { InboxJobData } from '../types.js'; @@ -68,11 +68,11 @@ export class InboxProcessorService implements OnApplicationShutdown { private queueLoggerService: QueueLoggerService, private idService: IdService, - @Inject(DI.activityContextRepository) - private activityContextRepository: ActivityContextRepository, + @Inject(DI.apContextsRepository) + private apContextsRepository: ApContextsRepository, - @Inject(DI.activityLogsRepository) - private activityLogsRepository: ActivityLogsRepository, + @Inject(DI.apInboxLogsRepository) + private apInboxLogsRepository: ApInboxLogsRepository, ) { this.logger = this.queueLoggerService.logger.createSubLogger('inbox'); this.updateInstanceQueue = new CollapsedQueue(process.env.NODE_ENV !== 'test' ? 60 * 1000 * 5 : 0, this.collapseUpdateInstanceJobs, this.performUpdateInstance); @@ -132,7 +132,7 @@ export class InboxProcessorService implements OnApplicationShutdown { } } - private async _process(job: Bull.Job, log?: SkActivityLog): Promise { + private async _process(job: Bull.Job, log?: SkApInboxLog): Promise { const signature = job.data.signature; // HTTP-signature let activity = job.data.activity; @@ -369,11 +369,11 @@ export class InboxProcessorService implements OnApplicationShutdown { await this.dispose(); } - private createLog(payload: IActivity, keyId: string): SkActivityLog { + private createLog(payload: IActivity, keyId: string): SkApInboxLog { const activity = Object.assign({}, payload, { '@context': undefined }) as unknown as JsonValue; const host = this.utilityService.extractDbHost(keyId); - const log = new SkActivityLog({ + const log = new SkApInboxLog({ id: this.idService.gen(), at: new Date(), verified: false, @@ -387,7 +387,7 @@ export class InboxProcessorService implements OnApplicationShutdown { if (context) { const md5 = createHash('md5').update(JSON.stringify(context)).digest('base64'); log.contextHash = md5; - log.context = new SkActivityContext({ + log.context = new SkApContext({ md5, json: context, }); @@ -396,18 +396,18 @@ export class InboxProcessorService implements OnApplicationShutdown { return log; } - private async recordLog(log: SkActivityLog): Promise { + private async recordLog(log: SkApInboxLog): Promise { if (log.context) { // https://stackoverflow.com/a/47064558 - await this.activityContextRepository - .createQueryBuilder('context_body') + await this.apContextsRepository + .createQueryBuilder('activity_context') .insert() - .into(SkActivityContext) + .into(SkApContext) .values(log.context) .orIgnore('md5') .execute(); } - await this.activityLogsRepository.upsert(log, ['id']); + await this.apInboxLogsRepository.upsert(log, ['id']); } } -- cgit v1.2.3-freya