Skip to content

Conversation

@ulemons
Copy link
Contributor

@ulemons ulemons commented Jan 14, 2026

Refactored findGlobalIntegrationsStatusCount and findGlobalIntegrations
These two functions were refactored to improve clarity and maintainability.
The new structure allows them to be executed in parallel, reducing overall execution time and improving performance.


Note

Improves performance and API consistency for global integrations queries.

  • Refactors findGlobalIntegrations to accept a filters object, normalize status, detect not-connected, and run fetch + count via Promise.all; returns { rows, count, limit, offset } with safe numeric coercion
  • Refactors findGlobalIntegrationsStatusCount to accept a filters object and perform status counts and not-connected count in parallel, merging results into a single array
  • Minor signature/typing cleanup in integrationRepository.ts without changing external behavior beyond the new filters parameter

Written by Cursor Bugbot for commit 2313879. This will update automatically on new commits. Configure here.

@ulemons ulemons changed the title feat: refactor integration api feat: refactor integration api (CM-809) Jan 14, 2026
@ulemons ulemons self-assigned this Jan 14, 2026
@ulemons ulemons requested review from Copilot and mbani01 January 14, 2026 16:43
@ulemons ulemons marked this pull request as ready for review January 14, 2026 16:44
Copy link
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 refactors two repository methods (findGlobalIntegrations and findGlobalIntegrationsStatusCount) to improve code structure and performance. The refactoring wraps parameters in a filters object for better organization and implements parallel query execution using Promise.all() to reduce overall execution time.

Changes:

  • Restructured function parameters to use a filters object instead of direct destructuring
  • Implemented parallel execution of data fetching and count queries in both methods
  • Improved consistency in count result handling with fallback values

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

])

// Both functions return an array with count objects, so we take the first element
const count = (countResult as { count: number }[])[0]?.count
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The type cast here assumes countResult is always an array, but the destructuring pattern differs from the findGlobalIntegrationsStatusCount method (line 392) which uses [notConnectedResult] to explicitly destructure the first element. For consistency and clarity, consider destructuring countResult directly in the Promise.all statement as [rows, [countObj]] and accessing countObj.count without the type cast.

Copilot uses AI. Check for mistakes.
return [...rows, { status: 'not-connected', count: +result.count }]

// Execute both queries in parallel for better performance
const [statusCounts, [notConnectedResult]] = await Promise.all([
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

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

The destructuring pattern [notConnectedResult] assumes the function always returns a non-empty array. If fetchGlobalNotConnectedIntegrationsCount could potentially return an empty array, accessing notConnectedResult.count on line 401 would fail. Consider adding a fallback or validating the array is not empty before destructuring, similar to the optional chaining used in line 361.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants