mirror of
https://iceshrimp.dev/crimekillz/iceshrimp-161sh.git
synced 2024-11-22 04:03:49 +01:00
[backend] Also use RecursionLimiter for parseAudience and noteCreateService
This commit is contained in:
parent
4dd8fdbd04
commit
1cbfd68a39
@ -9,6 +9,7 @@ import type {
|
|||||||
CacheableUser,
|
CacheableUser,
|
||||||
} from "@/models/entities/user.js";
|
} from "@/models/entities/user.js";
|
||||||
import { User } from "@/models/entities/user.js";
|
import { User } from "@/models/entities/user.js";
|
||||||
|
import { RecursionLimiter } from "@/models/repositories/user-profile.js";
|
||||||
|
|
||||||
type Visibility = "public" | "home" | "followers" | "specified";
|
type Visibility = "public" | "home" | "followers" | "specified";
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ export async function parseAudience(
|
|||||||
to?: ApObject,
|
to?: ApObject,
|
||||||
cc?: ApObject,
|
cc?: ApObject,
|
||||||
resolver?: Resolver,
|
resolver?: Resolver,
|
||||||
|
limiter: RecursionLimiter = new RecursionLimiter(20)
|
||||||
): Promise<AudienceInfo> {
|
): Promise<AudienceInfo> {
|
||||||
const toGroups = groupingAudience(getApIds(to), actor);
|
const toGroups = groupingAudience(getApIds(to), actor);
|
||||||
const ccGroups = groupingAudience(getApIds(cc), actor);
|
const ccGroups = groupingAudience(getApIds(cc), actor);
|
||||||
@ -33,7 +35,7 @@ export async function parseAudience(
|
|||||||
const mentionedUsers = (
|
const mentionedUsers = (
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
others.map((id) =>
|
others.map((id) =>
|
||||||
limit(() => resolvePerson(id, resolver).catch(() => null)),
|
limit(() => resolvePerson(id, resolver, limiter).catch(() => null)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
).filter((x): x is CacheableUser => x != null);
|
).filter((x): x is CacheableUser => x != null);
|
||||||
|
@ -176,7 +176,7 @@ export async function createNote(
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const noteAudience = await parseAudience(actor, note.to, note.cc);
|
const noteAudience = await parseAudience(actor, note.to, note.cc, undefined, limiter);
|
||||||
let visibility = noteAudience.visibility;
|
let visibility = noteAudience.visibility;
|
||||||
const visibleUsers = noteAudience.visibleUsers;
|
const visibleUsers = noteAudience.visibleUsers;
|
||||||
|
|
||||||
@ -394,6 +394,7 @@ export async function createNote(
|
|||||||
url: url,
|
url: url,
|
||||||
},
|
},
|
||||||
silent,
|
silent,
|
||||||
|
limiter
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ import { shouldSilenceInstance } from "@/misc/should-block-instance.js";
|
|||||||
import meilisearch from "../../db/meilisearch.js";
|
import meilisearch from "../../db/meilisearch.js";
|
||||||
import { redisClient } from "@/db/redis.js";
|
import { redisClient } from "@/db/redis.js";
|
||||||
import { Mutex } from "redis-semaphore";
|
import { Mutex } from "redis-semaphore";
|
||||||
|
import { RecursionLimiter } from "@/models/repositories/user-profile.js";
|
||||||
|
|
||||||
const mutedWordsCache = new Cache<
|
const mutedWordsCache = new Cache<
|
||||||
{ userId: UserProfile["userId"]; mutedWords: UserProfile["mutedWords"] }[]
|
{ userId: UserProfile["userId"]; mutedWords: UserProfile["mutedWords"] }[]
|
||||||
@ -167,6 +168,7 @@ export default async (
|
|||||||
},
|
},
|
||||||
data: Option,
|
data: Option,
|
||||||
silent = false,
|
silent = false,
|
||||||
|
limiter: RecursionLimiter = new RecursionLimiter(20)
|
||||||
) =>
|
) =>
|
||||||
// rome-ignore lint/suspicious/noAsyncPromiseExecutor: FIXME
|
// rome-ignore lint/suspicious/noAsyncPromiseExecutor: FIXME
|
||||||
new Promise<Note>(async (res, rej) => {
|
new Promise<Note>(async (res, rej) => {
|
||||||
@ -292,7 +294,7 @@ export default async (
|
|||||||
emojis = data.apEmojis || extractCustomEmojisFromMfm(combinedTokens);
|
emojis = data.apEmojis || extractCustomEmojisFromMfm(combinedTokens);
|
||||||
|
|
||||||
mentionedUsers =
|
mentionedUsers =
|
||||||
data.apMentions || (await extractMentionedUsers(user, combinedTokens));
|
data.apMentions || (await extractMentionedUsers(user, combinedTokens, limiter));
|
||||||
}
|
}
|
||||||
|
|
||||||
tags = tags
|
tags = tags
|
||||||
@ -925,6 +927,7 @@ function incNotesCountOfUser(user: { id: User["id"] }) {
|
|||||||
export async function extractMentionedUsers(
|
export async function extractMentionedUsers(
|
||||||
user: { host: User["host"] },
|
user: { host: User["host"] },
|
||||||
tokens: mfm.MfmNode[],
|
tokens: mfm.MfmNode[],
|
||||||
|
limiter: RecursionLimiter = new RecursionLimiter(20)
|
||||||
): Promise<User[]> {
|
): Promise<User[]> {
|
||||||
if (tokens == null) return [];
|
if (tokens == null) return [];
|
||||||
|
|
||||||
@ -933,7 +936,7 @@ export async function extractMentionedUsers(
|
|||||||
let mentionedUsers = (
|
let mentionedUsers = (
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
mentions.map((m) =>
|
mentions.map((m) =>
|
||||||
resolveUser(m.username, m.host || user.host).catch(() => null),
|
resolveUser(m.username, m.host || user.host, undefined, limiter).catch(() => null),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
).filter((x) => x != null) as User[];
|
).filter((x) => x != null) as User[];
|
||||||
|
Loading…
Reference in New Issue
Block a user