Skip to content

Commit 3ac015d

Browse files
committed
fix: filter first relevant orgs to avoid timeouts
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent e6f6aba commit 3ac015d

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

  • services/libs/data-access-layer/src/affiliations

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,23 @@ export async function findWorkExperiencesBulk(
3333
): Promise<IWorkRow[]> {
3434
const rows: IWorkRow[] = await qx.select(
3535
`
36-
WITH aggs AS (
36+
WITH relevant_orgs AS (
37+
SELECT DISTINCT "organizationId"
38+
FROM "memberOrganizations"
39+
WHERE "memberId" IN ($(memberIds:csv))
40+
AND "deletedAt" IS NULL
41+
),
42+
aggs AS (
3743
SELECT
3844
osa."organizationId",
3945
sum(osa."memberCount") AS total_count
4046
FROM "organizationSegmentsAgg" osa
41-
WHERE osa."segmentId" IN (
42-
SELECT id FROM segments
43-
WHERE "grandparentId" IS NOT NULL
44-
AND "parentId" IS NOT NULL
45-
)
47+
WHERE osa."organizationId" IN (SELECT "organizationId" FROM relevant_orgs)
48+
AND osa."segmentId" IN (
49+
SELECT id FROM segments
50+
WHERE "grandparentId" IS NOT NULL
51+
AND "parentId" IS NOT NULL
52+
)
4653
GROUP BY osa."organizationId"
4754
)
4855
SELECT

0 commit comments

Comments
 (0)