@@ -82,31 +82,53 @@ export class HostsService {
8282 serverDescription = undefined ;
8383 }
8484
85- const { inbound : inboundObj , nodes, excludedInternalSquads, ...rest } = dto ;
85+ const { inbounds , nodes, excludedInternalSquads, ...rest } = dto ;
8686
87- const configProfile = await this . queryBus . execute (
88- new GetConfigProfileByUuidQuery ( inboundObj . configProfileUuid ) ,
89- ) ;
87+ const validatedInbounds = [ ] as { configProfileUuid : string ; configProfileInboundUuid : string } [ ] ;
88+ const configProfileCache = new Map < string , Awaited < ReturnType < typeof this . queryBus . execute > > > ( ) ;
9089
91- if ( ! configProfile . isOk ) {
92- return fail ( ERRORS . CONFIG_PROFILE_NOT_FOUND ) ;
93- }
90+ for ( const inbound of inbounds ) {
91+ if ( ! configProfileCache . has ( inbound . configProfileUuid ) ) {
92+ const configProfile = await this . queryBus . execute (
93+ new GetConfigProfileByUuidQuery ( inbound . configProfileUuid ) ,
94+ ) ;
95+ configProfileCache . set ( inbound . configProfileUuid , configProfile ) ;
96+ }
9497
95- const configProfileInbound = configProfile . response . inbounds . find (
96- ( inbound ) => inbound . uuid === inboundObj . configProfileInboundUuid ,
97- ) ;
98- if ( ! configProfileInbound ) {
99- return fail ( ERRORS . CONFIG_PROFILE_INBOUND_NOT_FOUND_IN_SPECIFIED_PROFILE ) ;
98+ const configProfile = configProfileCache . get ( inbound . configProfileUuid ) ! ;
99+
100+ if ( ! configProfile . isOk ) {
101+ return fail ( ERRORS . CONFIG_PROFILE_NOT_FOUND ) ;
102+ }
103+
104+ const configProfileInbound = configProfile . response . inbounds . find (
105+ ( profileInbound ) => profileInbound . uuid === inbound . configProfileInboundUuid ,
106+ ) ;
107+ if ( ! configProfileInbound ) {
108+ return fail ( ERRORS . CONFIG_PROFILE_INBOUND_NOT_FOUND_IN_SPECIFIED_PROFILE ) ;
109+ }
110+
111+ validatedInbounds . push ( {
112+ configProfileUuid : inbound . configProfileUuid ,
113+ configProfileInboundUuid : inbound . configProfileInboundUuid ,
114+ } ) ;
100115 }
101116
117+ const primaryInbound = validatedInbounds [ 0 ] ;
118+
102119 const hostEntity = new HostsEntity ( {
103120 ...rest ,
104121 address : dto . address . trim ( ) ,
105122 xHttpExtraParams,
106123 muxParams,
107124 sockoptParams,
108- configProfileUuid : configProfile . response . uuid ,
109- configProfileInboundUuid : configProfileInbound . uuid ,
125+ configProfileUuid : primaryInbound . configProfileUuid ,
126+ configProfileInboundUuid : primaryInbound . configProfileInboundUuid ,
127+ configProfileInboundUuids : validatedInbounds . map ( ( inbound ) => inbound . configProfileInboundUuid ) ,
128+ configProfileInboundMappings : validatedInbounds . map ( ( inbound ) => ( {
129+ configProfileInboundUuid : inbound . configProfileInboundUuid ,
130+ configProfileUuid : inbound . configProfileUuid ,
131+ } ) ) ,
110132 serverDescription,
111133 } ) ;
112134
@@ -143,7 +165,7 @@ export class HostsService {
143165
144166 public async updateHost ( dto : UpdateHostRequestDto ) : Promise < TResult < HostsEntity > > {
145167 try {
146- const { inbound : inboundObj , nodes, excludedInternalSquads, ...rest } = dto ;
168+ const { inbounds , nodes, excludedInternalSquads, ...rest } = dto ;
147169
148170 const host = await this . hostsRepository . findByUUID ( dto . uuid ) ;
149171 if ( ! host ) return fail ( ERRORS . HOST_NOT_FOUND ) ;
@@ -208,25 +230,51 @@ export class HostsService {
208230
209231 let configProfileUuid : string | undefined ;
210232 let configProfileInboundUuid : string | undefined ;
211- if ( inboundObj ) {
212- const configProfile = await this . queryBus . execute (
213- new GetConfigProfileByUuidQuery ( inboundObj . configProfileUuid ) ,
214- ) ;
215-
216- if ( ! configProfile . isOk ) {
217- return fail ( ERRORS . CONFIG_PROFILE_NOT_FOUND ) ;
218- }
219-
220- const configProfileInbound = configProfile . response . inbounds . find (
221- ( inbound ) => inbound . uuid === inboundObj . configProfileInboundUuid ,
222- ) ;
223-
224- if ( ! configProfileInbound ) {
225- return fail ( ERRORS . CONFIG_PROFILE_INBOUND_NOT_FOUND_IN_SPECIFIED_PROFILE ) ;
233+ let configProfileInboundUuids : string [ ] | undefined ;
234+ let configProfileInboundMappings :
235+ | { configProfileInboundUuid : string ; configProfileUuid : string } [ ]
236+ | undefined ;
237+
238+ if ( inbounds ) {
239+ const validatedInbounds = [ ] as { configProfileUuid : string ; configProfileInboundUuid : string } [ ] ;
240+ const configProfileCache = new Map < string , Awaited < ReturnType < typeof this . queryBus . execute > > > ( ) ;
241+
242+ for ( const inbound of inbounds ) {
243+ if ( ! configProfileCache . has ( inbound . configProfileUuid ) ) {
244+ const configProfile = await this . queryBus . execute (
245+ new GetConfigProfileByUuidQuery ( inbound . configProfileUuid ) ,
246+ ) ;
247+ configProfileCache . set ( inbound . configProfileUuid , configProfile ) ;
248+ }
249+
250+ const configProfile = configProfileCache . get ( inbound . configProfileUuid ) ! ;
251+
252+ if ( ! configProfile . isOk ) {
253+ return fail ( ERRORS . CONFIG_PROFILE_NOT_FOUND ) ;
254+ }
255+
256+ const configProfileInbound = configProfile . response . inbounds . find (
257+ ( profileInbound ) => profileInbound . uuid === inbound . configProfileInboundUuid ,
258+ ) ;
259+
260+ if ( ! configProfileInbound ) {
261+ return fail ( ERRORS . CONFIG_PROFILE_INBOUND_NOT_FOUND_IN_SPECIFIED_PROFILE ) ;
262+ }
263+
264+ validatedInbounds . push ( {
265+ configProfileUuid : inbound . configProfileUuid ,
266+ configProfileInboundUuid : inbound . configProfileInboundUuid ,
267+ } ) ;
226268 }
227269
228- configProfileUuid = configProfile . response . uuid ;
229- configProfileInboundUuid = configProfileInbound . uuid ;
270+ const primaryInbound = validatedInbounds [ 0 ] ;
271+ configProfileUuid = primaryInbound . configProfileUuid ;
272+ configProfileInboundUuid = primaryInbound . configProfileInboundUuid ;
273+ configProfileInboundUuids = validatedInbounds . map ( ( inbound ) => inbound . configProfileInboundUuid ) ;
274+ configProfileInboundMappings = validatedInbounds . map ( ( inbound ) => ( {
275+ configProfileInboundUuid : inbound . configProfileInboundUuid ,
276+ configProfileUuid : inbound . configProfileUuid ,
277+ } ) ) ;
230278 }
231279
232280 if ( nodes !== undefined ) {
@@ -250,6 +298,8 @@ export class HostsService {
250298 sockoptParams,
251299 configProfileUuid,
252300 configProfileInboundUuid,
301+ configProfileInboundUuids,
302+ configProfileInboundMappings,
253303 serverDescription,
254304 } ) ;
255305
0 commit comments