Jon/construct cache key and show (#3242)
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
|
||||
@@ -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 };
|
||||
|
||||
Reference in New Issue
Block a user