Procházet zdrojové kódy

Prefetch timeline tasks and harden concurrent task loading

Execution tasks were previously seeded from the
executions embedded in the transfer details payload.
That payload no longer carries them, so tasks are
now fetched from the dedicated per-execution
endpoint instead.

Signed-off-by: Mihaela Balutoiu <mbalutoiu@cloudbasesolutions.com>
Mihaela Balutoiu před 2 měsíci
rodič
revize
fd8f51f650
1 změnil soubory, kde provedl 67 přidání a 20 odebrání
  1. 67 20
      src/stores/TransferStore.ts

+ 67 - 20
src/stores/TransferStore.ts

@@ -130,6 +130,7 @@ class TransferStore {
         this.executionsHasOlderPage = hasOlderPage;
         this.executionsHasOlderPage = hasOlderPage;
         this.executionsLoading = false;
         this.executionsLoading = false;
       });
       });
+      this.prefetchExecutionsTasks(raw);
     } catch (err) {
     } catch (err) {
       runInAction(() => {
       runInAction(() => {
         this.executionsLoading = false;
         this.executionsLoading = false;
@@ -171,6 +172,7 @@ class TransferStore {
         this.executionsHasOlderPage = hasOlderPage;
         this.executionsHasOlderPage = hasOlderPage;
         this.executionsPaginationLoading = false;
         this.executionsPaginationLoading = false;
       });
       });
+      this.prefetchExecutionsTasks(raw);
     } catch (err) {
     } catch (err) {
       runInAction(() => {
       runInAction(() => {
         this.executionsHasOlderPage = false;
         this.executionsHasOlderPage = false;
@@ -365,55 +367,100 @@ class TransferStore {
 
 
   currentlyLoadingExecution = "";
   currentlyLoadingExecution = "";
 
 
+  private loadingExecutionTaskIds: Set<string> = new Set();
+
   @action async getExecutionTasks(options: {
   @action async getExecutionTasks(options: {
     transferId: string;
     transferId: string;
     executionId?: string;
     executionId?: string;
     polling?: boolean;
     polling?: boolean;
   }) {
   }) {
     const { transferId: transferId, executionId, polling } = options;
     const { transferId: transferId, executionId, polling } = options;
-
-    if (!polling && this.currentlyLoadingExecution === executionId) {
-      return;
-    }
-    this.currentlyLoadingExecution = polling
+    const targetId = polling
       ? this.currentlyLoadingExecution
       ? this.currentlyLoadingExecution
       : executionId || "";
       : executionId || "";
-    if (!this.currentlyLoadingExecution) {
-      return;
-    }
-
-    if (
-      !polling &&
-      this.executionsTasks.find(e => e.id === this.currentlyLoadingExecution)
-    ) {
+    if (!targetId) {
       return;
       return;
     }
     }
 
 
     if (!polling) {
     if (!polling) {
+      this.currentlyLoadingExecution = targetId;
+      if (this.executionsTasks.find(e => e.id === targetId)) {
+        this.executionsTasksLoading = false;
+        return;
+      }
+      if (this.loadingExecutionTaskIds.has(targetId)) {
+        this.executionsTasksLoading = true;
+        return;
+      }
+      this.loadingExecutionTaskIds.add(targetId);
       this.executionsTasksLoading = true;
       this.executionsTasksLoading = true;
     }
     }
 
 
     try {
     try {
       const executionTasks = await TransferSource.getExecutionTasks({
       const executionTasks = await TransferSource.getExecutionTasks({
         transferId: transferId,
         transferId: transferId,
-        executionId: this.currentlyLoadingExecution,
+        executionId: targetId,
         polling,
         polling,
       });
       });
       runInAction(() => {
       runInAction(() => {
         this.executionsTasks = [
         this.executionsTasks = [
-          ...this.executionsTasks.filter(
-            e => e.id !== this.currentlyLoadingExecution,
-          ),
+          ...this.executionsTasks.filter(e => e.id !== targetId),
           executionTasks,
           executionTasks,
         ];
         ];
       });
       });
     } catch (err) {
     } catch (err) {
       console.error(err);
       console.error(err);
     } finally {
     } finally {
-      runInAction(() => {
-        this.executionsTasksLoading = false;
-      });
+      if (!polling) {
+        runInAction(() => {
+          this.loadingExecutionTaskIds.delete(targetId);
+          if (this.currentlyLoadingExecution === targetId) {
+            this.executionsTasksLoading = false;
+          }
+        });
+      }
+    }
+  }
+
+  @action async prefetchExecutionsTasks(
+    executions: Execution[],
+  ): Promise<void> {
+    const transferId = this.transferDetails?.id;
+    if (!transferId) {
+      return;
     }
     }
+    await Promise.all(
+      executions.map(async execution => {
+        if (
+          this.executionsTasks.find(e => e.id === execution.id) ||
+          this.loadingExecutionTaskIds.has(execution.id)
+        ) {
+          return;
+        }
+        this.loadingExecutionTaskIds.add(execution.id);
+        try {
+          const executionTasks = await TransferSource.getExecutionTasks({
+            transferId,
+            executionId: execution.id,
+            polling: true,
+          });
+          runInAction(() => {
+            if (!this.executionsTasks.find(e => e.id === execution.id)) {
+              this.executionsTasks = [...this.executionsTasks, executionTasks];
+            }
+            if (this.currentlyLoadingExecution === execution.id) {
+              this.executionsTasksLoading = false;
+            }
+          });
+        } catch (err) {
+          console.error(err);
+        } finally {
+          runInAction(() => {
+            this.loadingExecutionTaskIds.delete(execution.id);
+          });
+        }
+      }),
+    );
   }
   }
 
 
   @action async execute(transferId: string, fields?: Field[]): Promise<void> {
   @action async execute(transferId: string, fields?: Field[]): Promise<void> {