Skip to content

Commit 7094336

Browse files
add getFullWorkflowCached function to workflowStore
1 parent f3c2574 commit 7094336

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

client/src/stores/workflowStore.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import { computed, ref, set } from "vue";
33

44
import { GalaxyApi } from "@/api";
55
import type { StoredWorkflowDetailed } from "@/api/workflows";
6+
import { getWorkflowFull } from "@/components/Workflow/workflows.services";
67

78
export const useWorkflowStore = defineStore("workflowStore", () => {
89
const workflowsByInstanceId = ref<{ [index: string]: StoredWorkflowDetailed }>({});
10+
const fullWorkflowsByIdAndVersion = ref(new Map<string, any>());
911

1012
const getStoredWorkflowByInstanceId = computed(() => (workflowId: string) => {
1113
return workflowsByInstanceId.value[workflowId];
@@ -25,6 +27,22 @@ export const useWorkflowStore = defineStore("workflowStore", () => {
2527
}
2628
});
2729

30+
// TODO: A better way? Could use ref<{ [id: string]: { [version: string]: any } }>({});
31+
function uniqueIdAndVersionKey(workflowId: string, version?: number) {
32+
return `${workflowId}${version ? `_${version}` : "_latest"}`;
33+
}
34+
async function getFullWorkflowCached(workflowId: string, version?: number) {
35+
const key = uniqueIdAndVersionKey(workflowId, version);
36+
if (fullWorkflowsByIdAndVersion.value.has(key)) {
37+
return fullWorkflowsByIdAndVersion.value.get(key);
38+
}
39+
const storedWorkflow = await getWorkflowFull(workflowId, version);
40+
if (storedWorkflow) {
41+
fullWorkflowsByIdAndVersion.value.set(key, storedWorkflow);
42+
}
43+
return storedWorkflow;
44+
}
45+
2846
// stores in progress promises to avoid overlapping requests
2947
const workflowDetailPromises = new Map<string, Promise<unknown>>();
3048

@@ -68,6 +86,7 @@ export const useWorkflowStore = defineStore("workflowStore", () => {
6886
return {
6987
fetchWorkflowForInstanceId,
7088
fetchWorkflowForInstanceIdCached,
89+
getFullWorkflowCached,
7190
getStoredWorkflowByInstanceId,
7291
getStoredWorkflowIdByInstanceId,
7392
getStoredWorkflowNameByInstanceId,

0 commit comments

Comments
 (0)