Jon/construct cache key and show (#3242)

This commit is contained in:
Jonathan Dobson
2025-08-20 13:47:17 -04:00
committed by GitHub
parent 55bc6bd367
commit 0913e4f0a0
4 changed files with 81 additions and 15 deletions

View File

@@ -57,6 +57,7 @@ import {
layout,
startNode,
} from "./workflowEditorUtils";
import { constructCacheKeyValue } from "./utils";
const Constants = {
NewBrowserCooldown: 30000,
@@ -130,7 +131,13 @@ function Workspace({
const initialHeight = (initialWidth / 16) * 9;
// ---end fya
const cacheKey = workflow?.cache_key ?? "";
const cacheKeyValue =
cacheKey === "" ? "" : constructCacheKeyValue(cacheKey, workflow);
const { data: blockScripts } = useBlockScriptsQuery({
cacheKey,
cacheKeyValue,
workflowPermanentId,
});

View File

@@ -97,4 +97,36 @@ const getInitialParameters = (workflow: WorkflowApiResponse) => {
.filter(Boolean) as ParametersState;
};
export { getInitialParameters };
/**
* Attempt to construct a valid cache key value from the workflow parameters.
*/
const constructCacheKeyValue = (
cacheKey: string,
workflow: WorkflowApiResponse,
) => {
const workflowParameters = getInitialParameters(workflow)
.filter((p) => p.parameterType === "workflow")
.reduce(
(acc, parameter) => {
acc[parameter.key] = parameter.defaultValue;
return acc;
},
{} as Record<string, unknown>,
);
for (const [name, value] of Object.entries(workflowParameters)) {
if (value === null || value === undefined || value === "") {
continue;
}
cacheKey = cacheKey.replace(`{{${name}}}`, value.toString());
}
if (cacheKey.includes("{") || cacheKey.includes("}")) {
return "";
}
return cacheKey;
};
export { constructCacheKeyValue, getInitialParameters };