@@ -7,10 +7,6 @@ import {
77 IIntegrationConfigService ,
88 INTEGRATION_CONFIG_SERVICE_TOKEN ,
99} from '@libs/integrations/domain/integrationConfigs/contracts/integration-config.service.contracts' ;
10- import {
11- IIntegrationService ,
12- INTEGRATION_SERVICE_TOKEN ,
13- } from '@libs/integrations/domain/integrations/contracts/integration.service.contracts' ;
1410import {
1511 IParametersService ,
1612 PARAMETERS_SERVICE_TOKEN ,
@@ -21,8 +17,6 @@ export class ContextResolutionService implements IContextResolutionService {
2117 constructor (
2218 @Inject ( PARAMETERS_SERVICE_TOKEN )
2319 private readonly parametersService : IParametersService ,
24- @Inject ( INTEGRATION_SERVICE_TOKEN )
25- private readonly integrationService : IIntegrationService ,
2620 @Inject ( INTEGRATION_CONFIG_SERVICE_TOKEN )
2721 private readonly integrationConfigService : IIntegrationConfigService ,
2822 ) { }
@@ -31,44 +25,33 @@ export class ContextResolutionService implements IContextResolutionService {
3125 organizationId : string ,
3226 repositoryId : string ,
3327 ) : Promise < string > {
34- // 1. Fetch all active integrations for the organization
35- const integrations = await this . integrationService . find ( {
36- organization : { uuid : organizationId } ,
37- status : true ,
38- } ) ;
28+ // Prior version fetched active integrations first, then issued
29+ // one `find({ integration: { uuid } })` per integration inside a
30+ // sequential loop — a textbook 1+N on the code-review hot path.
31+ // The repository method below collapses it to a single JOIN
32+ // query over integration_configs → integrations → organization.
33+ const integrationConfigs =
34+ await this . integrationConfigService . findByOrganizationAndConfigKey (
35+ organizationId ,
36+ IntegrationConfigKey . REPOSITORIES ,
37+ ) ;
3938
40- if ( ! integrations || integrations . length === 0 ) {
39+ if ( ! integrationConfigs || integrationConfigs . length === 0 ) {
4140 throw new Error ( 'No active integrations found for organization' ) ;
4241 }
4342
44- // 2. For each integration, fetch integration configs with REPOSITORIES key
45- for ( const integration of integrations ) {
46- const integrationConfigs = await this . integrationConfigService . find (
47- {
48- integration : { uuid : integration . uuid } ,
49- configKey : IntegrationConfigKey . REPOSITORIES ,
50- } ,
51- ) ;
43+ for ( const config of integrationConfigs ) {
44+ const repositories = config . configValue ;
5245
53- if ( ! integrationConfigs || integrationConfigs . length === 0 ) {
54- continue ;
55- }
46+ if ( Array . isArray ( repositories ) ) {
47+ const foundRepository = repositories . find (
48+ ( repo : any ) =>
49+ repo . id === repositoryId ||
50+ repo . id === repositoryId . toString ( ) ,
51+ ) ;
5652
57- // 3. Search the repository list for one with the same id
58- for ( const config of integrationConfigs ) {
59- const repositories = config . configValue ;
60-
61- if ( Array . isArray ( repositories ) ) {
62- const foundRepository = repositories . find (
63- ( repo : any ) =>
64- repo . id === repositoryId ||
65- repo . id === repositoryId . toString ( ) ,
66- ) ;
67-
68- if ( foundRepository ) {
69- // 4. Return the teamId from this integration config
70- return config ?. team ?. uuid ;
71- }
53+ if ( foundRepository ) {
54+ return config ?. team ?. uuid ;
7255 }
7356 }
7457 }
0 commit comments