Skip to content

Commit 4f0fd1e

Browse files
committed
cache pricingPlans
1 parent caa2fbd commit 4f0fd1e

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

services/static-webserver/client/source/class/osparc/node/TierSelectionView.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ qx.Class.define("osparc.node.TierSelectionView", {
4646
tiersLayout.add(tierBox);
4747

4848
const node = this.getNode();
49-
osparc.store.Services.fetchPricingPlansService(node.getKey(), node.getVersion())
49+
osparc.store.Services.getPricingPlan(node.getKey(), node.getVersion())
5050
.then(pricingPlans => {
5151
if (pricingPlans && "pricingUnits" in pricingPlans && pricingPlans["pricingUnits"].length) {
5252
const pricingUnits = pricingPlans["pricingUnits"].map(pricingUnitData => {

services/static-webserver/client/source/class/osparc/service/PricingUnitsList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ qx.Class.define("osparc.service.PricingUnitsList", {
4747
},
4848

4949
__fetchUnits: function() {
50-
osparc.store.Services.fetchPricingPlansService(this.__serviceMetadata["key"], this.__serviceMetadata["version"])
50+
osparc.store.Services.getPricingPlan(this.__serviceMetadata["key"], this.__serviceMetadata["version"])
5151
.then(data => this.__populateList(data["pricingUnits"]))
5252
.catch(err => {
5353
console.error(err);

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ qx.Class.define("osparc.store.Services", {
2222
__servicesCached: {},
2323
__servicesPromisesCached: {},
2424
__studyServicesPromisesCached: {},
25+
__pricingPlansCached: {},
2526

2627
getServicesLatest: function(useCache = true) {
2728
return new Promise(resolve => {
@@ -347,12 +348,25 @@ qx.Class.define("osparc.store.Services", {
347348
return msg;
348349
},
349350

350-
fetchPricingPlansService: function(serviceKey, serviceVersion) {
351+
getPricingPlan: function(serviceKey, serviceVersion) {
352+
// init the cache
353+
if (this.__pricingPlansCached === null) {
354+
this.__pricingPlansCached = {};
355+
}
356+
357+
const serviceUrl = osparc.data.Resources.getServiceUrl(serviceKey, serviceVersion)
358+
// check if the service is already cached
359+
if (serviceUrl in this.__pricingPlansCached) {
360+
return Promise.resolve(this.__pricingPlansCached[serviceUrl]);
361+
}
362+
351363
const plansParams = {
352-
url: osparc.data.Resources.getServiceUrl(serviceKey, serviceVersion)
364+
url: serviceUrl,
353365
};
354366
return osparc.data.Resources.fetch("services", "pricingPlans", plansParams)
355367
.then(pricingPlansData => {
368+
// store the fetched pricing plans in the cache
369+
this.__pricingPlansCached[serviceUrl] = pricingPlansData;
356370
return pricingPlansData;
357371
});
358372
},

services/static-webserver/client/source/class/osparc/study/NodePricingUnits.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ qx.Class.define("osparc.study.NodePricingUnits", {
100100
const studyId = this.getStudyId();
101101
const nodeId = this.getNodeId();
102102

103-
osparc.store.Services.fetchPricingPlansService(nodeKey, nodeVersion)
103+
osparc.store.Services.getPricingPlan(nodeKey, nodeVersion)
104104
.then(pricingPlanData => {
105105
if (pricingPlanData) {
106106
const unitParams = {

0 commit comments

Comments
 (0)