Skip to content

Commit 21dc90a

Browse files
committed
fix poco html exception issue
1 parent d0af328 commit 21dc90a

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • apps/backend/src/app/api/latest/internal/metrics

apps/backend/src/app/api/latest/internal/metrics/route.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ async function loadUsersByCountry(tenancy: Tenancy, prisma: PrismaClientTransact
4646
const userIds = users.map((user) => user.projectUserId);
4747
const scalingFactor = totalUsers > users.length ? totalUsers / users.length : 1;
4848

49+
// Build ClickHouse array literal inline in the query body (sent via POST) instead of
50+
// passing as query_params (sent as URL params) to avoid the HTTP form field size limit
51+
// when there are many user IDs. UUIDs contain only hex chars and dashes, but we escape
52+
// single quotes for safety.
53+
const userIdsArrayLiteral = `[${userIds.map(id => `'${id.replace(/'/g, "''")}'`).join(',')}]`;
54+
4955
const clickhouseClient = getClickhouseAdminClient();
5056
const res = await clickhouseClient.query({
5157
query: `
@@ -67,7 +73,7 @@ async function loadUsersByCountry(tenancy: Tenancy, prisma: PrismaClientTransact
6773
AND project_id = {projectId:String}
6874
AND branch_id = {branchId:String}
6975
AND user_id IS NOT NULL
70-
AND has({userIds:Array(String)}, assumeNotNull(user_id))
76+
AND has(${userIdsArrayLiteral}, assumeNotNull(user_id))
7177
)
7278
WHERE cc IS NOT NULL
7379
AND ({includeAnonymous:UInt8} = 1 OR is_anonymous = 0)
@@ -80,7 +86,6 @@ async function loadUsersByCountry(tenancy: Tenancy, prisma: PrismaClientTransact
8086
query_params: {
8187
projectId: tenancy.project.id,
8288
branchId: tenancy.branchId,
83-
userIds,
8489
includeAnonymous: includeAnonymous ? 1 : 0,
8590
},
8691
format: "JSONEachRow",

0 commit comments

Comments
 (0)