Skip to content

Commit a47c1b3

Browse files
committed
feat: revert to memberOrganizations
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent d4cc31c commit a47c1b3

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

backend/src/api/public/v1/dev-stats/getAffiliations.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { ok } from '@/utils/api'
1212
import { validateOrThrow } from '@/utils/validation'
1313

14-
const MAX_HANDLES = 50
14+
const MAX_HANDLES = 100
1515
const DEFAULT_PAGE_SIZE = 20
1616

1717
const bodySchema = z.object({

services/libs/data-access-layer/src/affiliations/index.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)