@@ -130,6 +130,7 @@ class TransferStore {
130130 this . executionsHasOlderPage = hasOlderPage ;
131131 this . executionsLoading = false ;
132132 } ) ;
133+ this . prefetchExecutionsTasks ( raw ) ;
133134 } catch ( err ) {
134135 runInAction ( ( ) => {
135136 this . executionsLoading = false ;
@@ -171,6 +172,7 @@ class TransferStore {
171172 this . executionsHasOlderPage = hasOlderPage ;
172173 this . executionsPaginationLoading = false ;
173174 } ) ;
175+ this . prefetchExecutionsTasks ( raw ) ;
174176 } catch ( err ) {
175177 runInAction ( ( ) => {
176178 this . executionsHasOlderPage = false ;
@@ -365,55 +367,100 @@ class TransferStore {
365367
366368 currentlyLoadingExecution = "" ;
367369
370+ private loadingExecutionTaskIds : Set < string > = new Set ( ) ;
371+
368372 @action async getExecutionTasks ( options : {
369373 transferId : string ;
370374 executionId ?: string ;
371375 polling ?: boolean ;
372376 } ) {
373377 const { transferId : transferId , executionId, polling } = options ;
374-
375- if ( ! polling && this . currentlyLoadingExecution === executionId ) {
376- return ;
377- }
378- this . currentlyLoadingExecution = polling
378+ const targetId = polling
379379 ? this . currentlyLoadingExecution
380380 : executionId || "" ;
381- if ( ! this . currentlyLoadingExecution ) {
382- return ;
383- }
384-
385- if (
386- ! polling &&
387- this . executionsTasks . find ( e => e . id === this . currentlyLoadingExecution )
388- ) {
381+ if ( ! targetId ) {
389382 return ;
390383 }
391384
392385 if ( ! polling ) {
386+ this . currentlyLoadingExecution = targetId ;
387+ if ( this . executionsTasks . find ( e => e . id === targetId ) ) {
388+ this . executionsTasksLoading = false ;
389+ return ;
390+ }
391+ if ( this . loadingExecutionTaskIds . has ( targetId ) ) {
392+ this . executionsTasksLoading = true ;
393+ return ;
394+ }
395+ this . loadingExecutionTaskIds . add ( targetId ) ;
393396 this . executionsTasksLoading = true ;
394397 }
395398
396399 try {
397400 const executionTasks = await TransferSource . getExecutionTasks ( {
398401 transferId : transferId ,
399- executionId : this . currentlyLoadingExecution ,
402+ executionId : targetId ,
400403 polling,
401404 } ) ;
402405 runInAction ( ( ) => {
403406 this . executionsTasks = [
404- ...this . executionsTasks . filter (
405- e => e . id !== this . currentlyLoadingExecution ,
406- ) ,
407+ ...this . executionsTasks . filter ( e => e . id !== targetId ) ,
407408 executionTasks ,
408409 ] ;
409410 } ) ;
410411 } catch ( err ) {
411412 console . error ( err ) ;
412413 } finally {
413- runInAction ( ( ) => {
414- this . executionsTasksLoading = false ;
415- } ) ;
414+ if ( ! polling ) {
415+ runInAction ( ( ) => {
416+ this . loadingExecutionTaskIds . delete ( targetId ) ;
417+ if ( this . currentlyLoadingExecution === targetId ) {
418+ this . executionsTasksLoading = false ;
419+ }
420+ } ) ;
421+ }
422+ }
423+ }
424+
425+ @action async prefetchExecutionsTasks (
426+ executions : Execution [ ] ,
427+ ) : Promise < void > {
428+ const transferId = this . transferDetails ?. id ;
429+ if ( ! transferId ) {
430+ return ;
416431 }
432+ await Promise . all (
433+ executions . map ( async execution => {
434+ if (
435+ this . executionsTasks . find ( e => e . id === execution . id ) ||
436+ this . loadingExecutionTaskIds . has ( execution . id )
437+ ) {
438+ return ;
439+ }
440+ this . loadingExecutionTaskIds . add ( execution . id ) ;
441+ try {
442+ const executionTasks = await TransferSource . getExecutionTasks ( {
443+ transferId,
444+ executionId : execution . id ,
445+ polling : true ,
446+ } ) ;
447+ runInAction ( ( ) => {
448+ if ( ! this . executionsTasks . find ( e => e . id === execution . id ) ) {
449+ this . executionsTasks = [ ...this . executionsTasks , executionTasks ] ;
450+ }
451+ if ( this . currentlyLoadingExecution === execution . id ) {
452+ this . executionsTasksLoading = false ;
453+ }
454+ } ) ;
455+ } catch ( err ) {
456+ console . error ( err ) ;
457+ } finally {
458+ runInAction ( ( ) => {
459+ this . loadingExecutionTaskIds . delete ( execution . id ) ;
460+ } ) ;
461+ }
462+ } ) ,
463+ ) ;
417464 }
418465
419466 @action async execute ( transferId : string , fields ?: Field [ ] ) : Promise < void > {
0 commit comments