Skip to content

Commit d8159e2

Browse files
authored
Few frontend optimizations (ITISFoundation#2823)
1 parent fcc70d3 commit d8159e2

File tree

6 files changed

+124
-54
lines changed

6 files changed

+124
-54
lines changed

services/web/client/source/class/osparc/data/model/Node.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ qx.Class.define("osparc.data.model.Node", {
254254
__posX: null,
255255
__posY: null,
256256
__unresponsiveRetries: null,
257+
__stopRequestingStatus: null,
257258

258259
getWorkbench: function() {
259260
return this.getStudy().getWorkbench();
@@ -496,7 +497,7 @@ qx.Class.define("osparc.data.model.Node", {
496497
});
497498
},
498499

499-
stopInBackend: function() {
500+
__deleteInBackend: function() {
500501
// remove node in the backend
501502
const params = {
502503
url: {
@@ -1051,29 +1052,23 @@ qx.Class.define("osparc.data.model.Node", {
10511052
},
10521053
__onNodeState: function(data) {
10531054
const serviceState = data["service_state"];
1055+
const nodeId = data["service_uuid"];
10541056
const status = this.getStatus();
1057+
console.log(serviceState);
10551058
switch (serviceState) {
10561059
case "idle": {
10571060
status.setInteractive("idle");
1058-
const interval = 1000;
1059-
qx.event.Timer.once(() => this.__nodeState(), this, interval);
1060-
break;
1061-
}
1062-
case "starting":
1063-
case "pulling": {
1064-
status.setInteractive(serviceState);
1065-
const interval = 5000;
1061+
const interval = 2000;
10661062
qx.event.Timer.once(() => this.__nodeState(), this, interval);
10671063
break;
10681064
}
10691065
case "pending": {
10701066
if (data["service_message"]) {
1071-
const serviceId = data["service_uuid"];
10721067
const serviceName = this.getLabel();
10731068
const serviceMessage = data["service_message"];
10741069
const msg = `The service "${serviceName}" is waiting for available ` +
10751070
`resources. Please inform support and provide the following message ` +
1076-
`in case this does not resolve in a few minutes: "${serviceId}" ` +
1071+
`in case this does not resolve in a few minutes: "${nodeId}" ` +
10771072
`reported "${serviceMessage}"`;
10781073
const msgData = {
10791074
nodeId: this.getNodeId(),
@@ -1086,12 +1081,17 @@ qx.Class.define("osparc.data.model.Node", {
10861081
qx.event.Timer.once(() => this.__nodeState(), this, interval);
10871082
break;
10881083
}
1084+
case "starting":
1085+
case "pulling": {
1086+
status.setInteractive(serviceState);
1087+
const interval = 5000;
1088+
qx.event.Timer.once(() => this.__nodeState(), this, interval);
1089+
break;
1090+
}
10891091
case "running": {
1090-
const nodeId = data["service_uuid"];
10911092
if (nodeId !== this.getNodeId()) {
10921093
return;
10931094
}
1094-
10951095
const {
10961096
srvUrl,
10971097
isDynamicV2
@@ -1114,15 +1114,15 @@ qx.Class.define("osparc.data.model.Node", {
11141114
this.fireDataEvent("showInLogger", msgData);
11151115
return;
11161116
}
1117-
11181117
default:
11191118
console.error(serviceState, "service state not supported");
11201119
break;
11211120
}
11221121
},
11231122
__nodeState: function() {
11241123
// Check if study is still there
1125-
if (this.getStudy() === null) {
1124+
if (this.getStudy() === null || this.__stopRequestingStatus === true) {
1125+
console.log("stop callign me");
11261126
return;
11271127
}
11281128
// Check if node is still there
@@ -1231,12 +1231,16 @@ qx.Class.define("osparc.data.model.Node", {
12311231
},
12321232

12331233
removeNode: function() {
1234-
this.stopInBackend();
1234+
this.__deleteInBackend();
12351235
this.removeIFrame();
12361236
this.__removeInnerNodes();
12371237
this.__detachFromParent();
12381238
},
12391239

1240+
stopRequestingStatus: function() {
1241+
this.__stopRequestingStatus = true;
1242+
},
1243+
12401244
removeIFrame: function() {
12411245
let iFrame = this.getIFrame();
12421246
if (iFrame) {

services/web/client/source/class/osparc/data/model/Study.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,18 @@ qx.Class.define("osparc.data.model.Study", {
435435
},
436436

437437
stopStudy: function() {
438-
this.removeIFrames();
438+
this.__stopRequestingStatus();
439+
this.__removeIFrames();
439440
},
440441

441-
removeIFrames: function() {
442+
__stopRequestingStatus: function() {
443+
const nodes = this.getWorkbench().getNodes(true);
444+
for (const node of Object.values(nodes)) {
445+
node.stopRequestingStatus();
446+
}
447+
},
448+
449+
__removeIFrames: function() {
442450
const nodes = this.getWorkbench().getNodes(true);
443451
for (const node of Object.values(nodes)) {
444452
node.removeIFrame();

services/web/client/source/class/osparc/desktop/MainPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ qx.Class.define("osparc.desktop.MainPage", {
107107
const dashboardBtn = this.__navBar.getChildControl("dashboard-button");
108108
dashboardBtn.setFetching(true);
109109
const studyId = this.__studyEditor.getStudy().getUuid();
110-
this.__studyEditor.updateStudyDocument()
110+
this.__studyEditor.updateStudyDocument(false)
111111
.then(() => {
112112
this.__studyEditor.closeEditor();
113113
this.__showDashboard();

services/web/client/source/class/osparc/desktop/StudyEditor.js

Lines changed: 69 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ qx.Class.define("osparc.desktop.StudyEditor", {
7777
this._add(viewsStack, {
7878
flex: 1
7979
});
80+
81+
this.__updatingStudy = 0;
8082
},
8183

8284
events: {
@@ -114,6 +116,8 @@ qx.Class.define("osparc.desktop.StudyEditor", {
114116
__slideshowView: null,
115117
__autoSaveTimer: null,
116118
__lastSavedStudy: null,
119+
__updatingStudy: null,
120+
__updateThrottled: null,
117121

118122
setStudyData: function(studyData) {
119123
return new Promise((resolve, reject) => {
@@ -158,6 +162,9 @@ qx.Class.define("osparc.desktop.StudyEditor", {
158162
study.buildWorkbench();
159163
study.openStudy()
160164
.then(() => {
165+
this.__workbenchView.setStudy(study);
166+
this.__slideshowView.setStudy(study);
167+
161168
study.initStudy();
162169

163170
osparc.data.Resources.get("organizations")
@@ -232,23 +239,32 @@ qx.Class.define("osparc.desktop.StudyEditor", {
232239
})
233240
.finally(() => this._hideLoadingPage());
234241

235-
this.__workbenchView.setStudy(study);
236-
this.__slideshowView.setStudy(study);
242+
this.__updatingStudy = 0;
237243
},
238244

239245
__reloadSnapshotsAndIterations: function() {
240-
const store = osparc.store.Store.getInstance();
241-
store.invalidate("snapshots");
242-
store.invalidate("iterations");
243-
244-
const study = this.getStudy();
245-
study.getSnapshots()
246-
.then(snapshots => {
247-
store.setSnapshots(snapshots);
248-
if (snapshots.length) {
249-
study.getIterations()
250-
.then(iterations => {
251-
store.setIterations(iterations);
246+
osparc.utils.DisabledPlugins.isVersionControlDisabled()
247+
.then(isVCDisabled => {
248+
if (!isVCDisabled) {
249+
const store = osparc.store.Store.getInstance();
250+
store.invalidate("snapshots");
251+
store.invalidate("iterations");
252+
253+
const study = this.getStudy();
254+
study.getSnapshots()
255+
.then(snapshots => {
256+
store.setSnapshots(snapshots);
257+
if (snapshots.length) {
258+
osparc.utils.DisabledPlugins.isMetaModelingDisabled()
259+
.then(isMMDisabled => {
260+
if (!isMMDisabled) {
261+
study.getIterations()
262+
.then(iterations => {
263+
store.setIterations(iterations);
264+
});
265+
}
266+
});
267+
}
252268
});
253269
}
254270
});
@@ -509,34 +525,45 @@ qx.Class.define("osparc.desktop.StudyEditor", {
509525
},
510526

511527
__startAutoSaveTimer: function() {
512-
const diffPatcher = osparc.wrapper.JsonDiffPatch.getInstance();
513528
// Save every 3 seconds
514529
const interval = 3000;
515530
let timer = this.__autoSaveTimer = new qx.event.Timer(interval);
516531
timer.addListener("interval", () => {
517532
if (!osparc.wrapper.WebSocket.getInstance().isConnected()) {
518533
return;
519534
}
520-
const newObj = this.getStudy().serialize();
521-
const delta = diffPatcher.diff(this.__lastSavedStudy, newObj);
522-
if (delta) {
523-
let deltaKeys = Object.keys(delta);
524-
// lastChangeDate and creationDate should not be taken into account as data change
525-
[
526-
"creationDate",
527-
"lastChangeDate"
528-
].forEach(prop => {
529-
const index = deltaKeys.indexOf(prop);
530-
if (index > -1) {
531-
deltaKeys.splice(index, 1);
532-
}
533-
});
534-
if (deltaKeys.length > 0) {
535+
this.__checkStudyChanges();
536+
}, this);
537+
timer.start();
538+
},
539+
540+
__checkStudyChanges: function() {
541+
const newObj = this.getStudy().serialize();
542+
const diffPatcher = osparc.wrapper.JsonDiffPatch.getInstance();
543+
const delta = diffPatcher.diff(this.__lastSavedStudy, newObj);
544+
if (delta) {
545+
let deltaKeys = Object.keys(delta);
546+
// lastChangeDate and creationDate should not be taken into account as data change
547+
[
548+
"creationDate",
549+
"lastChangeDate"
550+
].forEach(prop => {
551+
const index = deltaKeys.indexOf(prop);
552+
if (index > -1) {
553+
deltaKeys.splice(index, 1);
554+
}
555+
});
556+
557+
if (deltaKeys.length > 0) {
558+
if (this.__updatingStudy > 0) {
559+
// throttle update
560+
console.log("throttle update");
561+
this.__updateThrottled = true;
562+
} else {
535563
this.updateStudyDocument(false);
536564
}
537565
}
538-
}, this);
539-
timer.start();
566+
}
540567
},
541568

542569
__stopAutoSaveTimer: function() {
@@ -556,9 +583,10 @@ qx.Class.define("osparc.desktop.StudyEditor", {
556583
});
557584
}
558585

586+
this.__updatingStudy++;
559587
const newObj = this.getStudy().serialize();
560588
return this.getStudy().updateStudy(newObj, run)
561-
.then(data => {
589+
.then(() => {
562590
this.__lastSavedStudy = osparc.wrapper.JsonDiffPatch.getInstance().clone(newObj);
563591
})
564592
.catch(error => {
@@ -571,6 +599,14 @@ qx.Class.define("osparc.desktop.StudyEditor", {
571599
this.__getStudyLogger().error(null, "Error updating pipeline");
572600
// Need to throw the error to be able to handle it later
573601
throw error;
602+
})
603+
.finally(() => {
604+
this.__updatingStudy--;
605+
if (this.__updateThrottled && this.__updatingStudy === 0) {
606+
console.log("throttle update done");
607+
this.__updateThrottled = false;
608+
this.updateStudyDocument(false);
609+
}
574610
});
575611
},
576612

services/web/client/source/class/osparc/desktop/WorkbenchView.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,8 +807,20 @@ qx.Class.define("osparc.desktop.WorkbenchView", {
807807
flex: 1
808808
});
809809
this.__studyOptionsPage.add(this.__getSlideshowSection());
810-
this.__studyOptionsPage.add(this.__getSnapshotsSection());
811-
this.__studyOptionsPage.add(this.__getIterationsSection());
810+
811+
osparc.utils.DisabledPlugins.isVersionControlDisabled()
812+
.then(isDisabled => {
813+
if (!isDisabled) {
814+
this.__studyOptionsPage.add(this.__getSnapshotsSection());
815+
}
816+
});
817+
818+
osparc.utils.DisabledPlugins.isMetaModelingDisabled()
819+
.then(isDisabled => {
820+
if (!isDisabled) {
821+
this.__studyOptionsPage.add(this.__getIterationsSection());
822+
}
823+
});
812824
},
813825

814826
__getSlideshowSection: function() {

services/web/client/source/class/osparc/utils/DisabledPlugins.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ qx.Class.define("osparc.utils.DisabledPlugins", {
2626
EXPORT: "WEBSERVER_EXPORTER",
2727
DUPLICATE: "WEBSERVER_EXPORTER",
2828
SCICRUNCH: "WEBSERVER_SCICRUNCH",
29+
VERSION_CONTROL: "WEBSERVER_VERSION_CONTROL",
30+
META_MODELING: "WEBSERVER_META_MODELING",
2931

3032
isExportDisabled: function() {
3133
return this.self().isPluginDisabled(this.self().EXPORT);
@@ -39,6 +41,14 @@ qx.Class.define("osparc.utils.DisabledPlugins", {
3941
return this.self().isPluginDisabled(this.self().SCICRUNCH);
4042
},
4143

44+
isVersionControlDisabled: function() {
45+
return this.self().isPluginDisabled(this.self().VERSION_CONTROL);
46+
},
47+
48+
isMetaModelingDisabled: function() {
49+
return this.self().isPluginDisabled(this.self().META_MODELING);
50+
},
51+
4252
isPluginDisabled: function(key) {
4353
return new Promise((resolve, reject) => {
4454
osparc.data.Resources.get("statics")

0 commit comments

Comments
 (0)