You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2021/06/18 19:38:29 UTC

[airavata-django-portal] 12/20: AIRAVATA-3453 Fixed async caching logic

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

machristie pushed a commit to branch airavata-3453
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal.git

commit a1950f6fd155f5350f0efb9f8085007463e75a48
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Tue May 11 16:41:58 2021 -0400

    AIRAVATA-3453 Fixed async caching logic
---
 .../js/web-components/store.js                     | 32 ++++++++++------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/django_airavata/apps/workspace/static/django_airavata_workspace/js/web-components/store.js b/django_airavata/apps/workspace/static/django_airavata_workspace/js/web-components/store.js
index 866fcea..0388289 100644
--- a/django_airavata/apps/workspace/static/django_airavata_workspace/js/web-components/store.js
+++ b/django_airavata/apps/workspace/static/django_airavata_workspace/js/web-components/store.js
@@ -5,27 +5,23 @@ const CACHE = {
   WORKSPACE_PREFERENCES: null,
 };
 export async function getApplicationModule(applicationId) {
-  if (applicationId in CACHE.APPLICATION_MODULES) {
-    return CACHE.APPLICATION_MODULES[applicationId];
+  if (!(applicationId in CACHE.APPLICATION_MODULES)) {
+    const promise = services.ApplicationModuleService.retrieve({
+      lookup: applicationId,
+    });
+    CACHE.APPLICATION_MODULES[applicationId] = promise;
   }
-  const result = await services.ApplicationModuleService.retrieve({
-    lookup: applicationId,
-  });
-  CACHE.APPLICATION_MODULES[applicationId] = result;
-  return result;
+  return await CACHE.APPLICATION_MODULES[applicationId];
 }
 
 export async function getApplicationInterfaceForModule(applicationId) {
-  // TODO: I'm not sure this is the right pattern. Perhaps the promise should be
-  // put in the cache and the cache entry should be 'await'-ed.
-  if (applicationId in CACHE.APPLICATION_INTERFACES) {
-    return CACHE.APPLICATION_INTERFACES[applicationId];
+  if (!(applicationId in CACHE.APPLICATION_INTERFACES)) {
+    const promise = services.ApplicationModuleService.getApplicationInterface({
+      lookup: applicationId,
+    });
+    CACHE.APPLICATION_INTERFACES[applicationId] = promise;
   }
-  const result = await services.ApplicationModuleService.getApplicationInterface(
-    { lookup: applicationId }
-  );
-  CACHE.APPLICATION_INTERFACES[applicationId] = result;
-  return result;
+  return await CACHE.APPLICATION_INTERFACES[applicationId];
 }
 
 export async function saveExperiment(experiment) {
@@ -41,9 +37,9 @@ export async function saveExperiment(experiment) {
 
 export async function getWorkspacePreferences() {
   if (!CACHE.WORKSPACE_PREFERENCES) {
-    CACHE.WORKSPACE_PREFERENCES = await services.WorkspacePreferencesService.get();
+    CACHE.WORKSPACE_PREFERENCES = services.WorkspacePreferencesService.get();
   }
-  return CACHE.WORKSPACE_PREFERENCES;
+  return await CACHE.WORKSPACE_PREFERENCES;
 }
 
 export async function getDefaultProjectId() {