telegram: include lazy-load time in audit elapsedMs

This commit is contained in:
Gustavo Madeira Santana 2026-03-03 19:58:45 -05:00
parent d5a5b25e21
commit 479bcf9a7c
2 changed files with 8 additions and 17 deletions

View File

@ -11,25 +11,13 @@ const TELEGRAM_API_BASE = "https://api.telegram.org";
type TelegramApiOk<T> = { ok: true; result: T };
type TelegramApiErr = { ok: false; description?: string };
type TelegramGroupMembershipAuditData = Omit<TelegramGroupMembershipAudit, "elapsedMs">;
export async function auditTelegramGroupMembershipImpl(
params: AuditTelegramGroupMembershipParams,
): Promise<TelegramGroupMembershipAudit> {
const started = Date.now();
const token = params.token?.trim() ?? "";
if (!token || params.groupIds.length === 0) {
return {
ok: true,
checkedGroups: 0,
unresolvedGroups: 0,
hasWildcardUnmentionedGroups: false,
groups: [],
elapsedMs: Date.now() - started,
};
}
): Promise<TelegramGroupMembershipAuditData> {
const fetcher = params.proxyUrl ? makeProxyFetch(params.proxyUrl) : fetch;
const base = `${TELEGRAM_API_BASE}/bot${token}`;
const base = `${TELEGRAM_API_BASE}/bot${params.token}`;
const groups: TelegramGroupMembershipAuditEntry[] = [];
for (const chatId of params.groupIds) {
@ -82,6 +70,5 @@ export async function auditTelegramGroupMembershipImpl(
unresolvedGroups: 0,
hasWildcardUnmentionedGroups: false,
groups,
elapsedMs: Date.now() - started,
};
}

View File

@ -94,8 +94,12 @@ export async function auditTelegramGroupMembership(
// Lazy import to avoid pulling `undici` (ProxyAgent) into cold-path callers that only need
// `collectTelegramUnmentionedGroupIds` (e.g. config audits).
const { auditTelegramGroupMembershipImpl } = await loadAuditMembershipRuntime();
return await auditTelegramGroupMembershipImpl({
const result = await auditTelegramGroupMembershipImpl({
...params,
token,
});
return {
...result,
elapsedMs: Date.now() - started,
};
}