dedupe evaluation logic in Workspace

This commit is contained in:
Horizontal42 2026-08-09 15:57:25 +03:00 • committed by GitHub
parent edfa55e4dc
commit 3a657a2d5d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -32,8 +32,7 @@ export class Workspace {
constructor(private engine: SumEngine, private sheets: () => SheetSource[]) {} constructor(private engine: SumEngine, private sheets: () => SheetSource[]) {}
/** Evaluate a sheet as the user's active/open document — refs resolve live. */ private doEvaluate(sheetId: string, text: string): LineResult[] {
evaluateSheet(sheetId: string, text: string): LineResult[] {
this.resolving.add(sheetId); this.resolving.add(sheetId);
try { try {
return this.engine.evaluateDocument(text, (sheet, key) => this.resolveXRef(sheet, key)); return this.engine.evaluateDocument(text, (sheet, key) => this.resolveXRef(sheet, key));
@ -42,6 +41,11 @@ export class Workspace {
} }
} }
/** Evaluate a sheet as the user's active/open document — refs resolve live. */
evaluateSheet(sheetId: string, text: string): LineResult[] {
return this.doEvaluate(sheetId, text);
}
getCachedResults(sheet: SheetSource): LineResult[] { getCachedResults(sheet: SheetSource): LineResult[] {
return this.exportsFor(sheet).results; return this.exportsFor(sheet).results;
} }
@ -145,13 +149,7 @@ export class Workspace {
private exportsFor(sheet: SheetSource): SheetExports { private exportsFor(sheet: SheetSource): SheetExports {
const cached = this.cache.get(sheet.id); const cached = this.cache.get(sheet.id);
if (cached) return cached; if (cached) return cached;
this.resolving.add(sheet.id); const results = this.doEvaluate(sheet.id, sheet.text);
let results: LineResult[];
try {
results = this.engine.evaluateDocument(sheet.text, (s, k) => this.resolveXRef(s, k));
} finally {
this.resolving.delete(sheet.id);
}
const vars = new Map<string, Value>(); const vars = new Map<string, Value>();
for (const r of results) { for (const r of results) {
if (r.assign && r.value) vars.set(r.assign, r.value); if (r.assign && r.value) vars.set(r.assign, r.value);