diff --git a/.github/workflows/example-client.yml b/.github/workflows/example-client.yml index 79b37169..5dd9fc1d 100644 --- a/.github/workflows/example-client.yml +++ b/.github/workflows/example-client.yml @@ -40,10 +40,10 @@ jobs: # Build the index go run cmd/main.go -i examples/client/palo-alto.index -s description -jsonl examples/workspace/palo-alto.jsonl - + # Copy to client cp examples/workspace/palo-alto.jsonl examples/client - + # Build the js lib npm ci npm run build diff --git a/examples/client/index.html b/examples/client/index.html index 845b26e9..93bfe050 100644 --- a/examples/client/index.html +++ b/examples/client/index.html @@ -188,10 +188,10 @@

Results -

document.getElementById("execute").disabled = false; while (true) { document.getElementById("next").disabled = false; - await new Promise( - (resolve) => (document.getElementById("next").onclick = resolve), - ); - result = await appendResult(); + await new Promise( + (resolve) => (document.getElementById("next").onclick = resolve), + ); + result = await appendResult(); } } diff --git a/src/btree/btree.ts b/src/btree/btree.ts index 458a0f71..ac94f563 100644 --- a/src/btree/btree.ts +++ b/src/btree/btree.ts @@ -21,6 +21,9 @@ export class BTree { private readonly pageFieldType: FieldType; private readonly pageFieldWidth: number; + private rootNodeCache: Promise | null = null; + private rootPointerCache: Promise | null = null; + // insight attributes below private readonly entries: number; @@ -48,26 +51,26 @@ export class BTree { } async root(): Promise { - const mp = await this.meta.root(); - - if (!mp || mp.length === 0) { - return { - rootNode: null, - pointer: mp, - }; + if (!this.rootNodeCache || !this.rootPointerCache) { + this.rootPointerCache = this.meta.root(); + this.rootNodeCache = this.rootPointerCache.then((ptr) => + this.readNode(ptr), + ); } - const root = await this.readNode(mp); - if (!root) { + const rootNode = await this.rootNodeCache; + const pointer = await this.rootPointerCache; + + if (!rootNode) { return { rootNode: null, - pointer: mp, + pointer, }; } return { - rootNode: root, - pointer: mp, + rootNode, + pointer, }; }