From 80c928068289020bfb4caca132154e9cba3fd2fb Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Wed, 25 Oct 2023 18:11:30 +0200 Subject: [PATCH] [backend] Decrease default RecursionLimiter count to 10 --- packages/backend/src/models/repositories/user-profile.ts | 4 ++-- packages/backend/src/remote/activitypub/audience.ts | 2 +- packages/backend/src/remote/activitypub/models/mention.ts | 2 +- packages/backend/src/remote/activitypub/models/note.ts | 4 ++-- packages/backend/src/remote/activitypub/models/person.ts | 6 +++--- packages/backend/src/remote/resolve-user.ts | 2 +- packages/backend/src/services/note/create.ts | 4 ++-- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/backend/src/models/repositories/user-profile.ts b/packages/backend/src/models/repositories/user-profile.ts index 6e68ee018..36d2c8c38 100644 --- a/packages/backend/src/models/repositories/user-profile.ts +++ b/packages/backend/src/models/repositories/user-profile.ts @@ -12,7 +12,7 @@ const queue = new Semaphore(5); export const UserProfileRepository = db.getRepository(UserProfile).extend({ // We must never await this without promiseEarlyReturn, otherwise giant webring-style profile mention trees will cause the queue to stop working - async updateMentions(id: UserProfile["userId"], limiter: RecursionLimiter = new RecursionLimiter(20)){ + async updateMentions(id: UserProfile["userId"], limiter: RecursionLimiter = new RecursionLimiter()){ const profile = await this.findOneBy({ userId: id }); if (!profile) return; const tokens: mfm.MfmNode[] = []; @@ -51,7 +51,7 @@ async function populateMentions(tokens: mfm.MfmNode[], objectHost: string | null export class RecursionLimiter { private counter; private mutex = new Mutex(); - constructor(count: number = 20) { + constructor(count: number = 10) { this.counter = count; } diff --git a/packages/backend/src/remote/activitypub/audience.ts b/packages/backend/src/remote/activitypub/audience.ts index aa70c25b2..766e05148 100644 --- a/packages/backend/src/remote/activitypub/audience.ts +++ b/packages/backend/src/remote/activitypub/audience.ts @@ -24,7 +24,7 @@ export async function parseAudience( to?: ApObject, cc?: ApObject, resolver?: Resolver, - limiter: RecursionLimiter = new RecursionLimiter(20) + limiter: RecursionLimiter = new RecursionLimiter() ): Promise { const toGroups = groupingAudience(getApIds(to), actor); const ccGroups = groupingAudience(getApIds(cc), actor); diff --git a/packages/backend/src/remote/activitypub/models/mention.ts b/packages/backend/src/remote/activitypub/models/mention.ts index da19f0aa8..232b6ff18 100644 --- a/packages/backend/src/remote/activitypub/models/mention.ts +++ b/packages/backend/src/remote/activitypub/models/mention.ts @@ -10,7 +10,7 @@ import { RecursionLimiter } from "@/models/repositories/user-profile.js"; export async function extractApMentions( tags: IObject | IObject[] | null | undefined, - limiter: RecursionLimiter = new RecursionLimiter(20) + limiter: RecursionLimiter = new RecursionLimiter() ) { const hrefs = unique( extractApMentionObjects(tags).map((x) => x.href as string), diff --git a/packages/backend/src/remote/activitypub/models/note.ts b/packages/backend/src/remote/activitypub/models/note.ts index 713de0f45..4c0154f6c 100644 --- a/packages/backend/src/remote/activitypub/models/note.ts +++ b/packages/backend/src/remote/activitypub/models/note.ts @@ -109,7 +109,7 @@ export async function createNote( value: string | IObject, resolver?: Resolver, silent = false, - limiter: RecursionLimiter = new RecursionLimiter(20) + limiter: RecursionLimiter = new RecursionLimiter() ): Promise { if (resolver == null) resolver = new Resolver(); @@ -407,7 +407,7 @@ export async function createNote( export async function resolveNote( value: string | IObject, resolver?: Resolver, - limiter: RecursionLimiter = new RecursionLimiter(20) + limiter: RecursionLimiter = new RecursionLimiter() ): Promise { const uri = typeof value === "string" ? value : value.id; if (uri == null) throw new Error("missing uri"); diff --git a/packages/backend/src/remote/activitypub/models/person.ts b/packages/backend/src/remote/activitypub/models/person.ts index 0812f7e7d..84907558b 100644 --- a/packages/backend/src/remote/activitypub/models/person.ts +++ b/packages/backend/src/remote/activitypub/models/person.ts @@ -171,7 +171,7 @@ export async function createPerson( uri: string, resolver?: Resolver, subjectHost?: string, - limiter: RecursionLimiter = new RecursionLimiter(20) + limiter: RecursionLimiter = new RecursionLimiter() ): Promise { if (typeof uri !== "string") throw new Error("uri is not string"); @@ -644,7 +644,7 @@ export async function updatePerson( export async function resolvePerson( uri: string, resolver?: Resolver, - limiter: RecursionLimiter = new RecursionLimiter(20) + limiter: RecursionLimiter = new RecursionLimiter() ): Promise { if (typeof uri !== "string") throw new Error("uri is not string"); @@ -719,7 +719,7 @@ export async function analyzeAttachments( return { fields, services }; } -export async function updateFeatured(userId: User["id"], resolver?: Resolver, limiter: RecursionLimiter = new RecursionLimiter(20)) { +export async function updateFeatured(userId: User["id"], resolver?: Resolver, limiter: RecursionLimiter = new RecursionLimiter()) { const user = await Users.findOneByOrFail({ id: userId }); if (!Users.isRemoteUser(user)) return; if (!user.featured) return; diff --git a/packages/backend/src/remote/resolve-user.ts b/packages/backend/src/remote/resolve-user.ts index 6c78e13b9..9d4d10ba2 100644 --- a/packages/backend/src/remote/resolve-user.ts +++ b/packages/backend/src/remote/resolve-user.ts @@ -34,7 +34,7 @@ export async function resolveUser( username: string, host: string | null, refresh: refreshType = 'refresh', - limiter: RecursionLimiter = new RecursionLimiter(20) + limiter: RecursionLimiter = new RecursionLimiter() ): Promise { const usernameLower = username.toLowerCase(); diff --git a/packages/backend/src/services/note/create.ts b/packages/backend/src/services/note/create.ts index a451730bb..61c509c96 100644 --- a/packages/backend/src/services/note/create.ts +++ b/packages/backend/src/services/note/create.ts @@ -168,7 +168,7 @@ export default async ( }, data: Option, silent = false, - limiter: RecursionLimiter = new RecursionLimiter(20) + limiter: RecursionLimiter = new RecursionLimiter() ) => // rome-ignore lint/suspicious/noAsyncPromiseExecutor: FIXME new Promise(async (res, rej) => { @@ -927,7 +927,7 @@ function incNotesCountOfUser(user: { id: User["id"] }) { export async function extractMentionedUsers( user: { host: User["host"] }, tokens: mfm.MfmNode[], - limiter: RecursionLimiter = new RecursionLimiter(20) + limiter: RecursionLimiter = new RecursionLimiter() ): Promise { if (tokens == null) return [];