Skip to content

Commit e8c5d6b

Browse files
committed
cache hypertools and tutorials only
1 parent c04124d commit e8c5d6b

File tree

4 files changed

+59
-70
lines changed

4 files changed

+59
-70
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ qx.Class.define("osparc.dashboard.TutorialBrowser", {
6565
},
6666

6767
__tutorialStateReceived: function(templateId, state, errors) {
68+
osparc.store.Templates.getTutorials()
69+
// OM
6870
const idx = this._resourcesList.findIndex(study => study["uuid"] === templateId);
6971
if (idx > -1) {
7072
this._resourcesList[idx]["state"] = state;

services/static-webserver/client/source/class/osparc/desktop/organizations/TutorialsList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ qx.Class.define("osparc.desktop.organizations.TutorialsList", {
8686
item.subscribeToFilterGroup("organizationTutorialsList");
8787
item.addListener("openMoreInfo", e => {
8888
const templateId = e.getData()["key"];
89-
osparc.store.Templates.getTemplate(templateId)
89+
osparc.store.Templates.getTutorial(templateId)
9090
.then(templateData => {
9191
if (templateData) {
9292
templateData["resourceType"] = "template";

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

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,6 @@ qx.Class.define("osparc.store.Store", {
466466
});
467467
},
468468

469-
setTemplateState: function(templateId, state) {
470-
const templatesWStateCache = this.getTemplates();
471-
const idx = templatesWStateCache.findIndex(templateWStateCache => templateWStateCache["uuid"] === templateId);
472-
if (idx !== -1) {
473-
templatesWStateCache[idx]["state"] = state;
474-
}
475-
},
476-
477469
trashStudy: function(studyId) {
478470
const params = {
479471
url: {
@@ -511,11 +503,6 @@ qx.Class.define("osparc.store.Store", {
511503
});
512504
},
513505

514-
getTemplate: function(templateId) {
515-
const templates = this.getTemplates();
516-
return templates.find(template => template["uuid"] === templateId);
517-
},
518-
519506
deleteStudy: function(studyId) {
520507
const params = {
521508
url: {

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

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -19,107 +19,107 @@ qx.Class.define("osparc.store.Templates", {
1919
type: "static",
2020

2121
statics: {
22-
__templates: null,
23-
__templatesPromisesCached: null,
2422
__tutorials: null,
25-
__tutorialsPromisesCached: null,
23+
__tutorialsPromiseCached: null,
2624
__hypertools: null,
27-
__hypertoolsPromisesCached: null,
25+
__hypertoolsPromiseCached: null,
2826

2927
__fetchTemplatesPaginated: function(params, options) {
28+
params["url"]["templateType"] = osparc.data.model.StudyUI.TEMPLATE_TYPE;
3029
return osparc.data.Resources.fetch("templates", "getPageFilteredSorted", params, options)
31-
.then(resp => {
32-
const templates = resp.data;
33-
// add them to the list
34-
if (this.__templates) {
35-
templates.forEach(template => {
36-
const index = this.__templates.findIndex(t => t.uuid === template.uuid);
37-
if (index === -1) {
38-
this.__templates.push(template);
39-
} else {
40-
this.__templates[index] = template;
41-
}
42-
});
43-
}
44-
return resp;
45-
})
4630
.catch(err => osparc.FlashMessenger.logError(err));
4731
},
4832

4933
fetchTemplatesNonPublicPaginated: function(params, options) {
50-
params["url"]["templateType"] = osparc.data.model.StudyUI.TEMPLATE_TYPE;
5134
return this.__fetchTemplatesPaginated(params, options);
5235
},
5336

5437
fetchTemplatesPublicPaginated: function(params, options) {
55-
params["url"]["templateType"] = osparc.data.model.StudyUI.TEMPLATE_TYPE;
5638
return this.__fetchTemplatesPaginated(params, options);
5739
},
5840

59-
__fetchAllTemplates: function() {
60-
return this.__templatesPromisesCached = osparc.data.Resources.getInstance().getAllPages("templates")
61-
.then(templates => {
62-
this.__templates = templates;
63-
return templates;
41+
__fetchAllTutorials: function(params) {
42+
params["url"]["templateType"] = osparc.data.model.StudyUI.TUTORIAL_TYPE;
43+
return this.__tutorialsPromiseCached = osparc.data.Resources.getInstance().getAllPages("templates", params, "getPageFilteredSorted")
44+
.then(tutorials => {
45+
this.__tutorials = tutorials;
46+
return tutorials;
6447
})
6548
.catch(err => {
6649
osparc.FlashMessenger.logError(err);
6750
})
6851
.finally(() => {
69-
this.__templatesPromisesCached = null;
52+
this.__tutorialsPromiseCached = null;
7053
});
7154
},
7255

73-
getTemplates: function(useCache = true) {
74-
if (this.__templatesPromisesCached) {
75-
// fetching templates already in progress
76-
return this.__templatesPromisesCached;
77-
}
78-
79-
if (this.__templates === null) {
80-
// no templates cached, fetch them
81-
return this.__fetchAllTemplates();
82-
}
83-
84-
if (useCache) {
85-
// templates already cached, return them
86-
return new Promise(resolve => resolve(this.__templates));
87-
}
88-
// templates cached but force a refresh
89-
return this.__fetchAllTemplates();
56+
__fetchAllHypertools: function(params) {
57+
params["url"]["templateType"] = osparc.data.model.StudyUI.HYPERTOOL_TYPE;
58+
return this.__hypertoolsPromiseCached = osparc.data.Resources.getInstance().getAllPages("templates", params, "getPageFilteredSorted")
59+
.then(hypertools => {
60+
this.__hypertools = hypertools;
61+
return hypertools;
62+
})
63+
.catch(err => {
64+
osparc.FlashMessenger.logError(err);
65+
})
66+
.finally(() => {
67+
this.__hypertoolsPromiseCached = null;
68+
});
9069
},
9170

92-
getTutorials: function() {
71+
getTutorials: function(useCache = true) {
9372
const params = {
9473
url: {
95-
"templateType": osparc.data.model.StudyUI.TUTORIAL_TYPE,
9674
"orderBy": JSON.stringify({
9775
field: "last_change_date",
9876
direction: "desc"
9977
}),
10078
}
10179
};
102-
return osparc.data.Resources.getInstance().getAllPages("templates", params, "getPageFilteredSorted");
80+
81+
if (this.__tutorialsPromiseCached) {
82+
return this.__tutorialsPromiseCached;
83+
}
84+
85+
if (this.__tutorials === null) {
86+
// no tutorials cached, fetch them
87+
return this.__fetchAllTutorials(params);
88+
}
89+
90+
if (useCache) {
91+
// tutorials already cached, return them
92+
return new Promise(resolve => resolve(this.__tutorials));
93+
}
94+
95+
return this.__fetchAllTutorials(params);
10396
},
10497

105-
getHypertools: function() {
98+
getHypertools: function(useCache = true) {
10699
const params = {
107100
url: {
108-
"templateType": osparc.data.model.StudyUI.HYPERTOOL_TYPE,
109101
"orderBy": JSON.stringify({
110102
field: "last_change_date",
111103
direction: "desc"
112104
}),
113105
}
114106
};
115-
return osparc.data.Resources.getInstance().getAllPages("templates", params, "getPageFilteredSorted");
116-
},
117107

118-
getTemplate: function(templateId) {
119-
return this.getTemplates()
120-
.then(templates => {
121-
return templates.find(t => t.uuid === templateId);
122-
});
108+
if (this.__hypertoolsPromiseCached) {
109+
return this.__hypertoolsPromiseCached;
110+
}
111+
112+
if (this.__hypertools === null) {
113+
// no hypertools cached, fetch them
114+
return this.__fetchAllHypertools(params);
115+
}
116+
117+
if (useCache) {
118+
// hypertools already cached, return them
119+
return new Promise(resolve => resolve(this.__hypertools));
120+
}
121+
122+
return this.__fetchAllHypertools(params);
123123
},
124124
}
125125
});

0 commit comments

Comments
 (0)