This is an automated email from the ASF dual-hosted git repository.

pingsutw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/submarine.git


The following commit(s) were added to refs/heads/master by this push:
     new c495ee8e SUBMARINE-1341. Optimising experiment asynchronous refresh 
handling
c495ee8e is described below

commit c495ee8e41d85154057f28e4a3afe8d145b410e6
Author: cdmikechen <cdmikec...@apache.org>
AuthorDate: Fri Oct 7 11:47:00 2022 +0800

    SUBMARINE-1341. Optimising experiment asynchronous refresh handling
    
    ### What is this PR for?
    Experiment's asynchronous refresh will cancel the confirmation tooltip for 
the delete button.
    
    ### What type of PR is it?
    Improvement
    
    ### Todos
    * [x] - Adjust the asynchronous refresh logic to update only the changed 
values
    
    ### What is the Jira issue?
    https://issues.apache.org/jira/browse/SUBMARINE-1341
    
    ### How should this be tested?
    No.
    
    ### Screenshots (if appropriate)
    
    
https://user-images.githubusercontent.com/12069428/194464126-5087b544-d3de-4693-a734-ee27b7c4e70d.mov
    
    ### Questions:
    * Do the license files need updating? No
    * Are there breaking changes for older versions? No
    * Does this need new documentation? No
    
    Author: cdmikechen <cdmikec...@apache.org>
    
    Signed-off-by: Kevin <pings...@apache.org>
    
    Closes #1006 from cdmikechen/SUBMARINE-1341 and squashes the following 
commits:
    
    c430c7d9 [cdmikechen] Optimising experiment asynchronous refresh handling
---
 .../experiment-home/experiment-home.component.ts   | 63 ++++++++++++++++------
 1 file changed, 47 insertions(+), 16 deletions(-)

diff --git 
a/submarine-workbench/workbench-web/src/app/pages/workbench/experiment/experiment-home/experiment-home.component.ts
 
b/submarine-workbench/workbench-web/src/app/pages/workbench/experiment/experiment-home/experiment-home.component.ts
index 6a8ab7af..44e07557 100644
--- 
a/submarine-workbench/workbench-web/src/app/pages/workbench/experiment/experiment-home/experiment-home.component.ts
+++ 
b/submarine-workbench/workbench-web/src/app/pages/workbench/experiment/experiment-home/experiment-home.component.ts
@@ -23,6 +23,7 @@ import { ExperimentFormService } from 
'@submarine/services/experiment.form.servi
 import { ExperimentService } from '@submarine/services/experiment.service';
 import { NzMessageService } from 'ng-zorro-antd';
 import { interval } from 'rxjs';
+import { isEqual } from 'lodash';
 import { filter, mergeMap, take, tap, timeout, retryWhen } from 
'rxjs/operators';
 import { ExperimentFormComponent } from 
'./experiment-form/experiment-form.component';
 
@@ -38,7 +39,7 @@ export class ExperimentHomeComponent implements OnInit {
     because when we modify the array in child component,
     the modification will be sync to parent.
   */
-  experimentList: ExperimentInfo[];
+  experimentList: ExperimentInfo[] = [];
   isListLoading: boolean = true;
   checkedList: boolean[];
   selectAllChecked: boolean = false;
@@ -49,7 +50,7 @@ export class ExperimentHomeComponent implements OnInit {
   reloadInterval = interval(this.reloadPeriod);
   reloadSub = null;
 
-  //mlflow
+  // mlflow
   isMlflowLoading: boolean = true;
   mlflowUrl: string = '';
 
@@ -86,21 +87,52 @@ export class ExperimentHomeComponent implements OnInit {
     this.experimentService.fetchExperimentList().subscribe(
       (list) => {
         this.isListLoading = false;
-        this.experimentList = list;
+        // Partial refresh required
+        // exists list size
+        const currentListSize = this.experimentList.length;
+        // The backend returns a real-time list
+        const newListSize = list.length;
         const currentTime = new Date();
-        this.experimentList.forEach((item) => {
-          if (item.status === 'Succeeded') {
-            const finTime = new Date(item.finishedTime);
-            const runTime = new Date(item.runningTime);
-            const result = (finTime.getTime() - runTime.getTime()) / 1000;
-            item.duration = this.experimentService.durationHandle(result);
-          } else if (item.runningTime) {
-            const runTime = new Date(item.runningTime);
-            const result = (currentTime.getTime() - runTime.getTime()) / 1000;
-            item.duration = this.experimentService.durationHandle(result);
+        // for loop experiment list
+        for (let i = 0; i < newListSize; i++) {
+          // The latest experiment info
+          const experiment = list[i]
+          // If a new row is found, insert it directly into
+          if (i > currentListSize - 1) {
+            this.experimentList = [...this.experimentList, experiment]
+          } else {
+            // Otherwise compare relevant information and update
+            const item = this.experimentList[i];
+            // compare
+            const keys = Object.keys(item);
+            for (const key of keys) {
+              if (key !== 'duration' && !isEqual(item[key], experiment[key])) {
+                item[key] = experiment[key]
+              }
+            }
+            // cal duration
+            if (item.status === 'Succeeded') {
+              const finTime = new Date(item.finishedTime);
+              const runTime = new Date(item.runningTime);
+              const result = (finTime.getTime() - runTime.getTime()) / 1000;
+              item.duration = this.experimentService.durationHandle(result);
+            } else if (item.runningTime) {
+              const runTime = new Date(item.runningTime);
+              const result = (currentTime.getTime() - runTime.getTime()) / 
1000;
+              item.duration = this.experimentService.durationHandle(result);
+            } else {
+              const acceptedTime = new Date(item.acceptedTime);
+              const result = (currentTime.getTime() - acceptedTime.getTime()) 
/ 1000;
+              item.duration = this.experimentService.durationHandle(result);
+            }
           }
-        });
-        if(!isAutoReload){
+        }
+        // Delete redundant rows
+        if (currentListSize > newListSize) {
+          this.experimentList = this.experimentList.splice(0, newListSize - 
currentListSize);
+        }
+
+        if (!isAutoReload) {
           // If it is auto-reloading, we do not want to change the state of 
checkbox.
           this.checkedList = [];
           for (let i = 0; i < this.experimentList.length; i++) {
@@ -199,4 +231,3 @@ export class ExperimentHomeComponent implements OnInit {
       );
   }
 }
- 
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@submarine.apache.org
For additional commands, e-mail: dev-h...@submarine.apache.org

Reply via email to