Skip to content

feat: uses left join in query organizations#4016

Merged
ulemons merged 1 commit intomainfrom
fix/use-left-join-on-query-organization
Apr 17, 2026
Merged

feat: uses left join in query organizations#4016
ulemons merged 1 commit intomainfrom
fix/use-left-join-on-query-organization

Conversation

@ulemons
Copy link
Copy Markdown
Contributor

@ulemons ulemons commented Apr 13, 2026

Note

Medium Risk
Changes SQL join semantics for OrganizationRepository.findAndCountAll, which can alter which organizations appear (and counts) when aggregates are requested, especially for orgs lacking aggregate rows.

Overview
Updates the organizations advanced query in organizationRepository.ts to always LEFT JOIN organizationSegmentsAgg (previously INNER JOIN when include.aggregates was enabled).

This means organization list/count queries with aggregates will now include organizations even when no matching aggregate row exists for the requested segment (leaving aggregate fields NULL/coalesced), instead of filtering them out.

Reviewed by Cursor Bugbot for commit 2199c18. Bugbot is set up for automated code reviews on this repo. Configure here.

@ulemons ulemons self-assigned this Apr 13, 2026
@ulemons ulemons added the Bug Created by Linear-GitHub Sync label Apr 13, 2026
Copilot AI review requested due to automatic review settings April 13, 2026 10:20
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

1 similar comment
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes the organizations advanced query SQL to always use a LEFT JOIN to organizationSegmentsAgg, regardless of whether aggregate fields are requested, so organizations without matching aggregate rows are still returned.

Changes:

  • Replace the conditional INNER JOIN/LEFT JOIN selection for organizationSegmentsAgg with a consistent LEFT JOIN.
  • Preserve the segment join predicate while altering join semantics (no longer filtering organizations out via the join).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/src/database/repositories/organizationRepository.ts
Comment thread backend/src/database/repositories/organizationRepository.ts
@ulemons ulemons force-pushed the fix/use-left-join-on-query-organization branch from e4ff931 to 2199c18 Compare April 17, 2026 07:22
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ Jira Issue Key Missing

Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability.

Example:

  • feat: add user authentication (CM-123)
  • feat: add user authentication (IN-123)

Projects:

  • CM: Community Data Platform
  • IN: Insights

Please add a Jira issue key to your PR title.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2199c18. Configure here.

Comment thread backend/src/database/repositories/organizationRepository.ts
@ulemons ulemons merged commit 5c84350 into main Apr 17, 2026
16 checks passed
@ulemons ulemons deleted the fix/use-left-join-on-query-organization branch April 17, 2026 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Created by Linear-GitHub Sync

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants