Skip to content

Commit 88060a1

Browse files
committed
feat: simplify query
Signed-off-by: Umberto Sgueglia <usgueglia@contractor.linuxfoundation.org>
1 parent a37c39d commit 88060a1

1 file changed

Lines changed: 5 additions & 11 deletions

File tree

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

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,11 @@ export async function findWorkExperiencesBulk(
4040
AND "deletedAt" IS NULL
4141
),
4242
aggs AS (
43-
SELECT
44-
osa."organizationId",
45-
sum(osa."memberCount") AS total_count
46-
FROM "organizationSegmentsAgg" osa
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-
)
53-
GROUP BY osa."organizationId"
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"
5448
)
5549
SELECT
5650
mo.id,

0 commit comments

Comments
 (0)