From 2199c1899b573c58fcfbcbc2b71b734cf0db697f Mon Sep 17 00:00:00 2001 From: Umberto Sgueglia Date: Mon, 13 Apr 2026 12:19:50 +0200 Subject: [PATCH] feat: uses left join in query organizations Signed-off-by: Umberto Sgueglia --- .../database/repositories/organizationRepository.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/backend/src/database/repositories/organizationRepository.ts b/backend/src/database/repositories/organizationRepository.ts index 8934544178..2fbe0ef83a 100644 --- a/backend/src/database/repositories/organizationRepository.ts +++ b/backend/src/database/repositories/organizationRepository.ts @@ -1491,14 +1491,8 @@ class OrganizationRepository { SELECT ${fields} FROM organizations o - ${ - withAggregates - ? ` INNER JOIN "organizationSegmentsAgg" osa ON osa."organizationId" = o.id AND ${ - segmentId ? `osa."segmentId" = $(segmentId)` : `osa."segmentId" IS NULL` - }` - : ` LEFT JOIN "organizationSegmentsAgg" osa ON osa."organizationId" = o.id AND ${ - segmentId ? `osa."segmentId" = $(segmentId)` : `osa."segmentId" IS NULL` - }` + LEFT JOIN "organizationSegmentsAgg" osa ON osa."organizationId" = o.id AND ${ + segmentId ? `osa."segmentId" = $(segmentId)` : `osa."segmentId" IS NULL` } LEFT JOIN "organizationEnrichments" oe ON oe."organizationId" = o.id WHERE 1=1