Skip to content

Commit

Permalink
remove global map
Browse files Browse the repository at this point in the history
  • Loading branch information
friendlymatthew committed Feb 27, 2024
1 parent c95ef0a commit 428e26a
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/btree/multi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import { PageFile } from "./pagefile";
const PAGE_SIZE_BYTES = 4096;
export const maxUint64 = 2n ** 64n - 1n;

const globalMetaPageCache = new Map<
bigint,
Promise<{ data: ArrayBuffer; totalLength: number }[]>
>();

export class LinkedMetaPage {
private resolver: RangeResolver;
private offset: bigint;
private metaPagePromise?: Promise<
{ data: ArrayBuffer; totalLength: number }[]
>;

constructor(resolver: RangeResolver, offset: bigint) {
this.resolver = resolver;
this.offset = offset;
Expand Down Expand Up @@ -56,18 +55,16 @@ export class LinkedMetaPage {
private async getMetaPage(): Promise<
{ data: ArrayBuffer; totalLength: number }[]
> {
if (!globalMetaPageCache.has(this.offset)) {
const p = this.resolver([
if (!this.metaPagePromise) {
this.metaPagePromise = this.resolver([
{
start: Number(this.offset),
end: Number(this.offset) + PAGE_SIZE_BYTES - 1,
},
]);

globalMetaPageCache.set(this.offset, p);
}

return globalMetaPageCache.get(this.offset)!;
return this.metaPagePromise;
}

/**
Expand Down

0 comments on commit 428e26a

Please sign in to comment.