rename activity_log and activity_context to ap_inbox_log and ap_context
This commit is contained in:
parent
0979392925
commit
cc2edae7ab
11 changed files with 113 additions and 65 deletions
|
@ -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"`);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -8,7 +8,7 @@ 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 type { ApInboxLogsRepository } from '@/models/_.js';
|
||||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
import Logger from '@/logger.js';
|
||||
|
||||
|
@ -16,7 +16,7 @@ import Logger from '@/logger.js';
|
|||
export const scanInterval = 1000 * 60 * 10;
|
||||
|
||||
@Injectable()
|
||||
export class ActivityLogCleanupService implements OnApplicationShutdown {
|
||||
export class ApLogCleanupService implements OnApplicationShutdown {
|
||||
private readonly logger: Logger;
|
||||
private scanTimer: NodeJS.Timeout | null = null;
|
||||
|
||||
|
@ -24,8 +24,8 @@ export class ActivityLogCleanupService implements OnApplicationShutdown {
|
|||
@Inject(DI.config)
|
||||
private readonly config: Config,
|
||||
|
||||
@Inject(DI.activityLogsRepository)
|
||||
private readonly activityLogsRepository: ActivityLogsRepository,
|
||||
@Inject(DI.apInboxLogsRepository)
|
||||
private readonly apInboxLogsRepository: ApInboxLogsRepository,
|
||||
|
||||
loggerService: LoggerService,
|
||||
) {
|
||||
|
@ -51,7 +51,7 @@ export class ActivityLogCleanupService implements OnApplicationShutdown {
|
|||
const oldestAllowed = new Date(Date.now() - this.config.activityLogging.maxAge);
|
||||
|
||||
// Delete all logs older than the threshold.
|
||||
const { affected } = await this.activityLogsRepository.delete({
|
||||
const { affected } = await this.apInboxLogsRepository.delete({
|
||||
at: LessThan(oldestAllowed),
|
||||
});
|
||||
|
|
@ -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 {}
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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<SkActivityContext>),
|
||||
const $apContextRepository: Provider = {
|
||||
provide: DI.apContextsRepository,
|
||||
useFactory: (db: DataSource) => db.getRepository(SkApContext).extend(miRepository as MiRepository<SkApContext>),
|
||||
inject: [DI.db],
|
||||
};
|
||||
|
||||
const $activityLogsRepository: Provider = {
|
||||
provide: DI.activityLogsRepository,
|
||||
useFactory: (db: DataSource) => db.getRepository(SkActivityLog).extend(miRepository as MiRepository<SkActivityLog>),
|
||||
const $apInboxLogsRepository: Provider = {
|
||||
provide: DI.apInboxLogsRepository,
|
||||
useFactory: (db: DataSource) => db.getRepository(SkApInboxLog).extend(miRepository as MiRepository<SkApInboxLog>),
|
||||
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,
|
||||
|
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
import { Column, PrimaryColumn, Entity } from 'typeorm';
|
||||
|
||||
@Entity('activity_context')
|
||||
export class SkActivityContext {
|
||||
@Entity('ap_context')
|
||||
export class SkApContext {
|
||||
@PrimaryColumn('text', {
|
||||
primaryKeyConstraintName: 'PK_activity_context',
|
||||
primaryKeyConstraintName: 'PK_ap_context',
|
||||
})
|
||||
public md5: string;
|
||||
|
||||
|
@ -17,7 +17,7 @@ export class SkActivityContext {
|
|||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
public json: any;
|
||||
|
||||
constructor(data?: Partial<SkActivityContext>) {
|
||||
constructor(data?: Partial<SkApContext>) {
|
||||
if (data) {
|
||||
Object.assign(this, data);
|
||||
}
|
|
@ -4,19 +4,22 @@
|
|||
*/
|
||||
|
||||
import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn } from 'typeorm';
|
||||
import { SkActivityContext } from '@/models/SkActivityContext.js';
|
||||
import { SkApContext } from '@/models/SkApContext.js';
|
||||
import { MiUser } from '@/models/_.js';
|
||||
import { id } from './util/id.js';
|
||||
|
||||
@Entity('activity_log')
|
||||
export class SkActivityLog {
|
||||
/**
|
||||
* Records activities received in the inbox
|
||||
*/
|
||||
@Entity('ap_inbox_log')
|
||||
export class SkApInboxLog {
|
||||
@PrimaryColumn({
|
||||
...id(),
|
||||
primaryKeyConstraintName: 'PK_activity_log',
|
||||
primaryKeyConstraintName: 'PK_ap_inbox_log',
|
||||
})
|
||||
public id: string;
|
||||
|
||||
@Index('IDX_activity_log_at')
|
||||
@Index('IDX_ap_inbox_log_at')
|
||||
@Column('timestamptz')
|
||||
public at: Date;
|
||||
|
||||
|
@ -26,13 +29,21 @@ export class SkActivityLog {
|
|||
@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;
|
||||
|
||||
@Index('IDX_activity_log_host')
|
||||
/**
|
||||
* Instance that the activity was sent from.
|
||||
* Untrusted unless verified is true.
|
||||
*/
|
||||
@Index('IDX_ap_inbox_log_host')
|
||||
@Column('text')
|
||||
public host: string;
|
||||
|
||||
|
@ -57,16 +68,19 @@ export class SkActivityLog {
|
|||
})
|
||||
public contextHash: string | null;
|
||||
|
||||
@ManyToOne(() => SkActivityContext, {
|
||||
@ManyToOne(() => SkApContext, {
|
||||
onDelete: 'CASCADE',
|
||||
nullable: true,
|
||||
})
|
||||
@JoinColumn({
|
||||
name: 'context_hash',
|
||||
foreignKeyConstraintName: 'FK_activity_log_context_hash',
|
||||
foreignKeyConstraintName: 'FK_ap_inbox_log_context_hash',
|
||||
})
|
||||
public context: SkActivityContext | null;
|
||||
public context: SkApContext | null;
|
||||
|
||||
/**
|
||||
* ID of the user who signed this request.
|
||||
*/
|
||||
@Column({
|
||||
...id(),
|
||||
name: 'auth_user_id',
|
||||
|
@ -74,17 +88,20 @@ export class SkActivityLog {
|
|||
})
|
||||
public authUserId: string | null;
|
||||
|
||||
/**
|
||||
* User who signed this request.
|
||||
*/
|
||||
@ManyToOne(() => MiUser, {
|
||||
onDelete: 'CASCADE',
|
||||
nullable: true,
|
||||
})
|
||||
@JoinColumn({
|
||||
name: 'auth_user_id',
|
||||
foreignKeyConstraintName: 'FK_activity_log_auth_user_id',
|
||||
foreignKeyConstraintName: 'FK_ap_inbox_log_auth_user_id',
|
||||
})
|
||||
public authUser: MiUser | null;
|
||||
|
||||
constructor(data?: Partial<SkActivityLog>) {
|
||||
constructor(data?: Partial<SkApInboxLog>) {
|
||||
if (data) {
|
||||
Object.assign(this, data);
|
||||
}
|
|
@ -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<T extends ObjectLiteral> {
|
||||
|
@ -131,8 +131,8 @@ export const miRepository = {
|
|||
|
||||
export {
|
||||
SkLatestNote,
|
||||
SkActivityContext,
|
||||
SkActivityLog,
|
||||
SkApContext,
|
||||
SkApInboxLog,
|
||||
MiAbuseUserReport,
|
||||
MiAbuseReportNotificationRecipient,
|
||||
MiAccessToken,
|
||||
|
@ -233,8 +233,8 @@ export type HashtagsRepository = Repository<MiHashtag> & MiRepository<MiHashtag>
|
|||
export type InstancesRepository = Repository<MiInstance> & MiRepository<MiInstance>;
|
||||
export type MetasRepository = Repository<MiMeta> & MiRepository<MiMeta>;
|
||||
export type LatestNotesRepository = Repository<SkLatestNote> & MiRepository<SkLatestNote>;
|
||||
export type ActivityContextRepository = Repository<SkActivityContext> & MiRepository<SkActivityContext>;
|
||||
export type ActivityLogsRepository = Repository<SkActivityLog> & MiRepository<SkActivityLog>;
|
||||
export type ApContextsRepository = Repository<SkApContext> & MiRepository<SkApContext>;
|
||||
export type ApInboxLogsRepository = Repository<SkApInboxLog> & MiRepository<SkApInboxLog>;
|
||||
export type ModerationLogsRepository = Repository<MiModerationLog> & MiRepository<MiModerationLog>;
|
||||
export type MutingsRepository = Repository<MiMuting> & MiRepository<MiMuting>;
|
||||
export type RenoteMutingsRepository = Repository<MiRenoteMuting> & MiRepository<MiRenoteMuting>;
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<InboxJobData>, log?: SkActivityLog): Promise<string> {
|
||||
private async _process(job: Bull.Job<InboxJobData>, log?: SkApInboxLog): Promise<string> {
|
||||
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<void> {
|
||||
private async recordLog(log: SkApInboxLog): Promise<void> {
|
||||
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']);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue