Fix recursive table evaluation caching
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s

This commit is contained in:
Shinuwa 2026-09-10 14:38:12 +02:00
parent 34524d2961
commit 7521d50626
3 changed files with 66 additions and 7 deletions

View file

@ -166,17 +166,22 @@ export function evaluateTableCell(address, cells, dimensions, stack = []) {
}
function evaluateTableCellWithCache(address, cells, dimensions, stack, cache) {
if (!stack.length && cache.has(address)) return cache.get(address);
const raw = String(cells?.[address] || "").trim();
if (!raw) return { value: null, display: "", error: "empty" };
if (stack.includes(address)) return { value: null, display: "#CYCLE", error: "cycle" };
if (cache.has(address)) return cache.get(address);
const raw = String(cells?.[address] || "").trim();
if (!raw) {
const evaluated = { value: null, display: "", error: "empty" };
cache.set(address, evaluated);
return evaluated;
}
if (!raw.startsWith("=")) {
const value = parsePlainNumber(raw);
return value == null
const evaluated = value == null
? { value: null, display: raw, error: "" }
: { value, display: formatNumber(value), error: "" };
cache.set(address, evaluated);
return evaluated;
}
const result = evaluateFormula(raw.slice(1), (reference) => {
@ -189,12 +194,12 @@ function evaluateTableCellWithCache(address, cells, dimensions, stack, cache) {
if (result.error) {
const label = result.error === "cycle" ? "#CYCLE" : result.error === "division" ? "#DIV/0" : "#ERREUR";
const evaluated = { value: null, display: label, error: result.error };
if (!stack.length) cache.set(address, evaluated);
cache.set(address, evaluated);
return evaluated;
}
const evaluated = { value: result.value, display: formatNumber(result.value), error: "" };
if (!stack.length) cache.set(address, evaluated);
cache.set(address, evaluated);
return evaluated;
}