Skip to content

Commit 8f32d23

Browse files
committed
studyServicesPromisesCached
1 parent 037577c commit 8f32d23

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

services/static-webserver/client/source/class/osparc/dashboard/CardBase.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -526,12 +526,7 @@ qx.Class.define("osparc.dashboard.CardBase", {
526526
});
527527

528528
if (resourceData["resourceType"] === "study" || resourceData["resourceType"] === "template") {
529-
const params = {
530-
url: {
531-
studyId: this.getResourceData()["uuid"]
532-
}
533-
};
534-
osparc.data.Resources.fetch("studies", "getServices", params)
529+
osparc.store.Services.getStudyServices(this.getResourceData()["uuid"])
535530
.then(resp => {
536531
const services = resp["services"];
537532
resourceData["services"] = services;

services/static-webserver/client/source/class/osparc/dashboard/ResourceDetails.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ qx.Class.define("osparc.dashboard.ResourceDetails", {
194194
};
195195
Promise.all([
196196
osparc.data.Resources.fetch("studies", "getOne", params),
197-
osparc.data.Resources.fetch("studies", "getServices", params)
197+
osparc.store.Services.getStudyServices(this.__resourceData["uuid"]),
198198
])
199199
.then(values => {
200200
const updatedStudyData = values[0];

services/static-webserver/client/source/class/osparc/metadata/ServicesInStudyUpdate.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ qx.Class.define("osparc.metadata.ServicesInStudyUpdate", {
5757
});
5858
this._introText.add(introText);
5959
let msg = "";
60-
const params = {
61-
url: {
62-
studyId: this._studyData["uuid"]
63-
}
64-
};
65-
osparc.data.Resources.fetch("studies", "getServices", params)
60+
osparc.store.Services.getStudyServices(this._studyData["uuid"])
6661
.then(resp => {
6762
const services = resp["services"];
6863
if (osparc.study.Utils.getCantExecuteServices(services).length) {

services/static-webserver/client/source/class/osparc/store/Services.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ qx.Class.define("osparc.store.Services", {
2121
statics: {
2222
__servicesCached: {},
2323
__servicesPromisesCached: {},
24+
__studyServicesPromisesCached: {},
2425

2526
getServicesLatest: function(useCache = true) {
2627
return new Promise(resolve => {
@@ -141,6 +142,25 @@ qx.Class.define("osparc.store.Services", {
141142
});
142143
},
143144

145+
getStudyServices: function(studyId) {
146+
// avoid request deduplication
147+
if (studyId in this.__studyServicesPromisesCached) {
148+
return this.__studyServicesPromisesCached[studyId];
149+
}
150+
151+
const params = {
152+
url: {
153+
studyId
154+
}
155+
};
156+
this.__studyServicesPromisesCached[studyId] = osparc.data.Resources.fetch("studies", "getServices", params)
157+
.finally(() => {
158+
delete this.__studyServicesPromisesCached[studyId];
159+
});
160+
161+
return this.__studyServicesPromisesCached[studyId]
162+
},
163+
144164
__getAllVersions: function(key) {
145165
const services = this.__servicesCached;
146166
let versions = [];

0 commit comments

Comments
 (0)