Skip to content

Commit d4cc31c

Browse files
committed
feat: use join instead of in
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent b0d2507 commit d4cc31c

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

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

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ export async function findWorkExperiencesBulk(
4040
AND "deletedAt" IS NULL
4141
),
4242
aggs AS (
43-
SELECT "organizationId", COUNT(DISTINCT "memberId") AS total_count
44-
FROM "memberOrganizations"
45-
WHERE "organizationId" IN (SELECT "organizationId" FROM relevant_orgs)
46-
AND "deletedAt" IS NULL
47-
GROUP BY "organizationId"
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"
4850
)
4951
SELECT
5052
mo.id,

0 commit comments

Comments
 (0)