document-dataply 0.0.9-alpha.1 → 0.0.9-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -9990,6 +9990,11 @@ var DocumentSerializeStrategyAsync = class extends import_dataply.SerializeStrat
9990
9990
  this.txContext = txContext;
9991
9991
  this.treeKey = treeKey;
9992
9992
  }
9993
+ /**
9994
+ * readHead에서 할당된 headPk를 캐싱하여
9995
+ * writeHead에서 AsyncLocalStorage 컨텍스트 유실 시에도 사용할 수 있도록 함
9996
+ */
9997
+ cachedHeadPk = null;
9993
9998
  async id(isLeaf) {
9994
9999
  const tx = this.txContext.get();
9995
10000
  const pk = await this.api.insertAsOverflow("__BPTREE_NODE_PLACEHOLDER__", false, tx);
@@ -10022,20 +10027,25 @@ var DocumentSerializeStrategyAsync = class extends import_dataply.SerializeStrat
10022
10027
  const pk = await this.api.insertAsOverflow("__BPTREE_HEAD_PLACEHOLDER__", false, tx);
10023
10028
  metadata.indices[this.treeKey][0] = pk;
10024
10029
  await this.api.updateDocumentInnerMetadata(metadata, tx);
10030
+ this.cachedHeadPk = pk;
10025
10031
  return null;
10026
10032
  }
10033
+ this.cachedHeadPk = headPk;
10027
10034
  const row = await this.api.select(headPk, false, tx);
10028
10035
  if (row === null || row === "" || row.startsWith("__BPTREE_")) return null;
10029
10036
  return JSON.parse(row);
10030
10037
  }
10031
10038
  async writeHead(head) {
10032
10039
  const tx = this.txContext.get();
10033
- const metadata = await this.api.getDocumentInnerMetadata(tx);
10034
- const indexInfo = metadata.indices[this.treeKey];
10035
- if (!indexInfo) {
10036
- throw new Error(`Index info not found for tree: ${this.treeKey}. Initialization should be handled outside.`);
10040
+ let headPk = this.cachedHeadPk;
10041
+ if (headPk === null) {
10042
+ const metadata = await this.api.getDocumentInnerMetadata(tx);
10043
+ const indexInfo = metadata.indices[this.treeKey];
10044
+ if (!indexInfo) {
10045
+ throw new Error(`Index info not found for tree: ${this.treeKey}. Initialization should be handled outside.`);
10046
+ }
10047
+ headPk = indexInfo[0];
10037
10048
  }
10038
- const headPk = indexInfo[0];
10039
10049
  const json = JSON.stringify(head);
10040
10050
  await this.api.update(headPk, json, tx);
10041
10051
  }
@@ -5,6 +5,11 @@ export declare class DocumentSerializeStrategyAsync<T extends Primitive> extends
5
5
  protected readonly api: DocumentDataplyAPI<any>;
6
6
  protected readonly txContext: DocumentDataplyAPI<any>['txContext'];
7
7
  readonly treeKey: string;
8
+ /**
9
+ * readHead에서 할당된 headPk를 캐싱하여
10
+ * writeHead에서 AsyncLocalStorage 컨텍스트 유실 시에도 사용할 수 있도록 함
11
+ */
12
+ private cachedHeadPk;
8
13
  constructor(order: number, api: DocumentDataplyAPI<any>, txContext: DocumentDataplyAPI<any>['txContext'], treeKey: string);
9
14
  id(isLeaf: boolean): Promise<string>;
10
15
  read(id: string): Promise<BPTreeNode<number, DataplyTreeValue<T>>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-dataply",
3
- "version": "0.0.9-alpha.1",
3
+ "version": "0.0.9-alpha.2",
4
4
  "description": "Simple and powerful JSON document database supporting complex queries and flexible indexing policies.",
5
5
  "license": "MIT",
6
6
  "author": "izure <admin@izure.org>",