Move caching to language service
This commit is contained in:
@@ -48,17 +48,11 @@ const defaultOptions: Required<WorkflowTemplateConverterOptions> = {
|
||||
};
|
||||
|
||||
export async function convertWorkflowTemplate(
|
||||
uri: string,
|
||||
context: TemplateContext,
|
||||
root: TemplateToken,
|
||||
fileProvider?: FileProvider,
|
||||
options: WorkflowTemplateConverterOptions = defaultOptions
|
||||
): Promise<WorkflowTemplate> {
|
||||
const cachedResult = workflowTemplateCache.get(uri)
|
||||
if (cachedResult) {
|
||||
return cachedResult;
|
||||
}
|
||||
|
||||
const result = {} as WorkflowTemplate;
|
||||
const opts = getOptionsWithDefaults(options);
|
||||
|
||||
@@ -66,7 +60,6 @@ export async function convertWorkflowTemplate(
|
||||
result.errors = context.errors.getErrors().map(x => ({
|
||||
Message: x.message
|
||||
}));
|
||||
workflowTemplateCache.set(uri, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -138,7 +131,6 @@ export async function convertWorkflowTemplate(
|
||||
}
|
||||
}
|
||||
|
||||
workflowTemplateCache.set(uri, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -155,11 +147,3 @@ function getOptionsWithDefaults(options: WorkflowTemplateConverterOptions): Requ
|
||||
errorPolicy: options.errorPolicy !== undefined ? options.errorPolicy : defaultOptions.errorPolicy
|
||||
};
|
||||
}
|
||||
|
||||
export function clearWorkflowTemplateCacheEntry(uri: string) {
|
||||
workflowTemplateCache.delete(uri);
|
||||
}
|
||||
|
||||
export function clearWorkflowTemplateCache() {
|
||||
workflowTemplateCache.clear();
|
||||
}
|
||||
@@ -7,8 +7,6 @@ import {WORKFLOW_ROOT} from "./workflow-constants";
|
||||
import {getWorkflowSchema} from "./workflow-schema";
|
||||
import {YamlObjectReader} from "./yaml-object-reader";
|
||||
|
||||
const parsedWorkflowCache = new Map<string, ParseWorkflowResult>();
|
||||
|
||||
export interface ParseWorkflowResult {
|
||||
context: TemplateContext;
|
||||
value: TemplateToken | undefined;
|
||||
@@ -17,11 +15,6 @@ export interface ParseWorkflowResult {
|
||||
export function parseWorkflow(entryFile: File, trace: TraceWriter): ParseWorkflowResult;
|
||||
export function parseWorkflow(entryFile: File, context: TemplateContext): ParseWorkflowResult;
|
||||
export function parseWorkflow(entryFile: File, contextOrTrace: TraceWriter | TemplateContext): ParseWorkflowResult {
|
||||
const cachedResult = parsedWorkflowCache.get(entryFile.name)
|
||||
if (cachedResult) {
|
||||
return cachedResult;
|
||||
}
|
||||
|
||||
const context =
|
||||
contextOrTrace instanceof TemplateContext
|
||||
? contextOrTrace
|
||||
@@ -38,7 +31,6 @@ export function parseWorkflow(entryFile: File, contextOrTrace: TraceWriter | Tem
|
||||
context,
|
||||
value: undefined
|
||||
};
|
||||
parsedWorkflowCache.set(entryFile.name, result);
|
||||
return result
|
||||
}
|
||||
const templateToken = templateReader.readTemplate(context, WORKFLOW_ROOT, reader, fileId);
|
||||
@@ -47,14 +39,5 @@ export function parseWorkflow(entryFile: File, contextOrTrace: TraceWriter | Tem
|
||||
context,
|
||||
value: templateToken
|
||||
} satisfies ParseWorkflowResult;
|
||||
parsedWorkflowCache.set(entryFile.name, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
export function clearParsedCacheEntry(path: string) {
|
||||
parsedWorkflowCache.delete(path);
|
||||
}
|
||||
|
||||
export function clearParsedCache() {
|
||||
parsedWorkflowCache.clear();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user