mirror of
https://github.com/Horizontal42/summarum.git
synced 2026-11-11 02:12:00 +03:00
Optimize numeric search with cached evaluate results
Co-authored-by: Horizontal42 <75383519+Horizontal42@users.noreply.github.com>
This commit is contained in:
parent
f5b1fc038b
commit
b3b7514f6c
2 changed files with 7 additions and 2 deletions
|
|
@ -49,7 +49,7 @@ function searchAllSheets(deps: SearchDeps, query: string): SearchHit[] {
|
||||||
const th = rq.threshold.value;
|
const th = rq.threshold.value;
|
||||||
const hits: SearchHit[] = [];
|
const hits: SearchHit[] = [];
|
||||||
for (const doc of docs) {
|
for (const doc of docs) {
|
||||||
const results = deps.workspace.evaluateSheet(doc.id, doc.text);
|
const results = deps.workspace.getCachedResults(doc);
|
||||||
const lines = doc.text.split("\n");
|
const lines = doc.text.split("\n");
|
||||||
for (let i = 0; i < results.length; i++) {
|
for (let i = 0; i < results.length; i++) {
|
||||||
const r = results[i];
|
const r = results[i];
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ interface SheetExports {
|
||||||
vars: Map<string, Value>;
|
vars: Map<string, Value>;
|
||||||
total: Value | null;
|
total: Value | null;
|
||||||
last: Value | null;
|
last: Value | null;
|
||||||
|
results: LineResult[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const XREF_SCAN_RE = /@(?:\[([^\]]+)\]|([\p{L}_][\p{L}\d_]*))\./gu;
|
const XREF_SCAN_RE = /@(?:\[([^\]]+)\]|([\p{L}_][\p{L}\d_]*))\./gu;
|
||||||
|
|
@ -40,6 +41,10 @@ export class Workspace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getCachedResults(sheet: SheetSource): LineResult[] {
|
||||||
|
return this.exportsFor(sheet).results;
|
||||||
|
}
|
||||||
|
|
||||||
/** Drop cached exports for a sheet and everything that transitively depends on it. */
|
/** Drop cached exports for a sheet and everything that transitively depends on it. */
|
||||||
invalidate(sheetId: string): void {
|
invalidate(sheetId: string): void {
|
||||||
const dirty = new Set<string>([sheetId]);
|
const dirty = new Set<string>([sheetId]);
|
||||||
|
|
@ -146,7 +151,7 @@ export class Workspace {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const exports: SheetExports = { vars, total: this.engine.totalValueOf(results), last };
|
const exports: SheetExports = { vars, total: this.engine.totalValueOf(results), last, results };
|
||||||
// A cycle-interrupted pass produces incomplete/wrong exports (dropped
|
// A cycle-interrupted pass produces incomplete/wrong exports (dropped
|
||||||
// assignments, missing total) — don't let it poison the cache. Re-evaluate
|
// assignments, missing total) — don't let it poison the cache. Re-evaluate
|
||||||
// fresh on every query until the cycle is actually broken by an edit.
|
// fresh on every query until the cycle is actually broken by an edit.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue