File tree Expand file tree Collapse file tree
backend/src/api/public/v1/dev-stats
services/libs/data-access-layer/src/affiliations Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import {
1111import { ok } from '@/utils/api'
1212import { validateOrThrow } from '@/utils/validation'
1313
14- const MAX_HANDLES = 50
14+ const MAX_HANDLES = 100
1515const DEFAULT_PAGE_SIZE = 20
1616
1717const bodySchema = z . object ( {
Original file line number Diff line number Diff line change @@ -39,14 +39,16 @@ export async function findWorkExperiencesBulk(
3939 WHERE "memberId" IN ($(memberIds:csv))
4040 AND "deletedAt" IS NULL
4141 ),
42+ -- Note: this intentionally differs from the equivalent query in member-organization-affiliation/index.ts
43+ -- which uses organizationSegmentsAgg to compute memberCount. That approach scans a large
44+ -- aggregation table and causes timeouts in an API context. Here we count directly from
45+ -- memberOrganizations which is faster and sufficient for the tiebreaker use case.
4246 aggs AS (
43- SELECT osa."organizationId", sum(osa."memberCount") AS total_count
44- FROM "organizationSegmentsAgg" osa
45- JOIN segments s ON s.id = osa."segmentId"
46- AND s."grandparentId" IS NOT NULL
47- AND s."parentId" IS NOT NULL
48- WHERE osa."organizationId" IN (SELECT "organizationId" FROM relevant_orgs)
49- GROUP BY osa."organizationId"
47+ SELECT "organizationId", COUNT(DISTINCT "memberId") AS total_count
48+ FROM "memberOrganizations"
49+ WHERE "organizationId" IN (SELECT "organizationId" FROM relevant_orgs)
50+ AND "deletedAt" IS NULL
51+ GROUP BY "organizationId"
5052 )
5153 SELECT
5254 mo.id,
You can’t perform that action at this time.
0 commit comments