From c9feae3a28cd938b8cd35d2a2a58f2772802be90 Mon Sep 17 00:00:00 2001 From: Natty Date: Thu, 19 Dec 2024 17:26:02 +0100 Subject: [PATCH] Handle delivered JSONs as opaque objects to remove the need for repeated serialization --- packages/backend/src/mag/rpc-client.ts | 2 +- packages/backend/src/queue/index.ts | 18 +++++++++--------- .../backend/src/queue/processors/deliver.ts | 6 ------ packages/backend/src/queue/types.ts | 12 ++++++------ .../backend/src/remote/activitypub/request.ts | 2 +- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/packages/backend/src/mag/rpc-client.ts b/packages/backend/src/mag/rpc-client.ts index 514b29c430..53dc0bcc32 100644 --- a/packages/backend/src/mag/rpc-client.ts +++ b/packages/backend/src/mag/rpc-client.ts @@ -169,7 +169,7 @@ export async function magApGet(userId: string, url: string): Promise { }); } -export async function magApPost(userId: string, url: string, body: any): Promise { +export async function magApPost(userId: string, url: string, body: string): Promise { logger.debug(`AP POST to: ${url}`); return await rpcCall("/ap/post", { user_id: userId, diff --git a/packages/backend/src/queue/index.ts b/packages/backend/src/queue/index.ts index 1cb2d9e651..f87c67daa8 100644 --- a/packages/backend/src/queue/index.ts +++ b/packages/backend/src/queue/index.ts @@ -18,14 +18,14 @@ import {endedPollNotification} from "./processors/ended-poll-notification.js"; import {queueLogger} from "./logger.js"; import {getJobInfo} from "./get-job-info.js"; import { - backgroundQueue, - dbQueue, - deliverQueue, - endedPollNotificationQueue, - inboxQueue, - objectStorageQueue, - systemQueue, - webhookDeliverQueue, + backgroundQueue, + dbQueue, + deliverQueue, + endedPollNotificationQueue, + inboxQueue, + objectStorageQueue, + systemQueue, + webhookDeliverQueue, } from "./queues.js"; import type {ThinUser} from "./types.js"; @@ -165,7 +165,7 @@ export function deliver(user: ThinUser, content: unknown, to: string | null) { user: { id: user.id, }, - content, + content: JSON.stringify(content, null, 2), to, }; diff --git a/packages/backend/src/queue/processors/deliver.ts b/packages/backend/src/queue/processors/deliver.ts index 70effb871d..74036c6d2c 100644 --- a/packages/backend/src/queue/processors/deliver.ts +++ b/packages/backend/src/queue/processors/deliver.ts @@ -13,8 +13,6 @@ import type Bull from "bull"; const logger = new Logger("deliver"); -let latest: string | null = null; - export default async (job: Bull.Job) => { let host: string; try { @@ -29,10 +27,6 @@ export default async (job: Bull.Job) => { if (await shouldSkipInstance(puny)) return "skip"; try { - if (latest !== (latest = JSON.stringify(job.data.content, null, 2))) { - logger.debug(`delivering ${latest}`); - } - await request(job.data.user, job.data.to, job.data.content); // Update stats diff --git a/packages/backend/src/queue/types.ts b/packages/backend/src/queue/types.ts index b72b127894..4149e59302 100644 --- a/packages/backend/src/queue/types.ts +++ b/packages/backend/src/queue/types.ts @@ -1,15 +1,15 @@ -import type { DriveFile } from "@/models/entities/drive-file.js"; -import type { Note } from "@/models/entities/note"; -import type { User } from "@/models/entities/user.js"; -import type { Webhook } from "@/models/entities/webhook"; -import type { IActivity } from "@/remote/activitypub/type.js"; +import type {DriveFile} from "@/models/entities/drive-file.js"; +import type {Note} from "@/models/entities/note"; +import type {User} from "@/models/entities/user.js"; +import type {Webhook} from "@/models/entities/webhook"; +import type {IActivity} from "@/remote/activitypub/type.js"; import type httpSignature from "@peertube/http-signature"; export type DeliverJobData = { /** Actor */ user: ThinUser; /** Activity */ - content: unknown; + content: string; /** inbox URL to deliver */ to: string; }; diff --git a/packages/backend/src/remote/activitypub/request.ts b/packages/backend/src/remote/activitypub/request.ts index a33e5b2c02..af775cd4ee 100644 --- a/packages/backend/src/remote/activitypub/request.ts +++ b/packages/backend/src/remote/activitypub/request.ts @@ -1,7 +1,7 @@ import type {User} from "@/models/entities/user.js"; import {magApGet, magApPost} from "@/mag/rpc-client.js"; -export default async (user: { id: User["id"] }, url: string, body: any) => { +export default async (user: { id: User["id"] }, url: string, body: string) => { return await magApPost(user.id, url, body); };