document-dataply 0.0.10-alpha.8 → 0.0.11

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
@@ -11789,26 +11789,26 @@ var DeadlineChunker = class {
11789
11789
  * EWMA 평활화 계수
11790
11790
  */
11791
11791
  alpha;
11792
- constructor(targetMs = 14) {
11792
+ constructor(startChunkSize = 0, targetMs = 5, alpha = 0.5) {
11793
+ this.chunkSize = startChunkSize;
11793
11794
  this.targetMs = targetMs;
11794
- this.chunkSize = 50;
11795
+ this.alpha = alpha;
11795
11796
  this.ewmaMs = null;
11796
- this.alpha = 0.3;
11797
11797
  }
11798
11798
  /**
11799
11799
  * EWMA 평활화 계수를 사용하여 평균 처리 시간을 업데이트합니다.
11800
11800
  */
11801
- _updateEstimate(elapsed, count) {
11801
+ updateEstimate(elapsed, count) {
11802
11802
  const msPerItem = elapsed / count;
11803
11803
  this.ewmaMs = this.ewmaMs === null ? msPerItem : this.alpha * msPerItem + (1 - this.alpha) * this.ewmaMs;
11804
11804
  }
11805
11805
  /**
11806
11806
  * 현재 chunk size를 업데이트합니다.
11807
11807
  */
11808
- _nextChunkSize() {
11808
+ nextChunkSize() {
11809
11809
  if (!this.ewmaMs || this.ewmaMs === 0) return this.chunkSize;
11810
11810
  const next = Math.floor(this.targetMs / this.ewmaMs);
11811
- return Math.max(1, Math.min(next, 5e3));
11811
+ return Math.max(1, next);
11812
11812
  }
11813
11813
  /**
11814
11814
  * 주어진 items를 chunk로 분할하여 처리합니다.
@@ -11816,15 +11816,19 @@ var DeadlineChunker = class {
11816
11816
  async processInChunks(items, processFn) {
11817
11817
  let i = 0;
11818
11818
  let len = items.length;
11819
+ if (this.chunkSize === 0) {
11820
+ this.chunkSize = Math.floor(items.length / 100 * 5);
11821
+ }
11819
11822
  while (i < len) {
11820
11823
  const chunk = items.slice(i, i + this.chunkSize);
11824
+ const count = chunk.length;
11821
11825
  const start = performance.now();
11822
11826
  await processFn(chunk);
11823
11827
  const elapsed = performance.now() - start;
11824
- this._updateEstimate(elapsed, chunk.length);
11825
- this.chunkSize = this._nextChunkSize();
11826
- i += chunk.length;
11827
- await new Promise((resolve) => setImmediate(resolve));
11828
+ this.updateEstimate(elapsed, count);
11829
+ this.chunkSize = this.nextChunkSize();
11830
+ i += count;
11831
+ await new Promise(setImmediate);
11828
11832
  }
11829
11833
  }
11830
11834
  };
@@ -11898,7 +11902,12 @@ var MutationManager = class {
11898
11902
  flattenedData.push({ pk: -1, data: flattenDocument });
11899
11903
  ids.push(id);
11900
11904
  }
11901
- const pks = await this.api.insertBatch(dataplyDocuments, true, tx2);
11905
+ const pks = [];
11906
+ const documentChunker = new DeadlineChunker(1e4);
11907
+ await documentChunker.processInChunks(dataplyDocuments, async (chunk) => {
11908
+ const res = await this.api.insertBatch(chunk, true, tx2);
11909
+ pks.push(...res);
11910
+ });
11902
11911
  for (let i = 0, len = pks.length; i < len; i++) {
11903
11912
  flattenedData[i].pk = pks[i];
11904
11913
  }
@@ -11928,7 +11937,8 @@ var MutationManager = class {
11928
11937
  batchInsertData.push([item.pk, { k: item.pk, v: indexVal }]);
11929
11938
  }
11930
11939
  }
11931
- const chunker = new DeadlineChunker();
11940
+ const chunker = new DeadlineChunker(3e4);
11941
+ console.log(batchInsertData.length);
11932
11942
  await chunker.processInChunks(batchInsertData, async (chunk) => {
11933
11943
  const [error] = await catchPromise(treeTx.batchInsert(chunk));
11934
11944
  if (error) {
@@ -18,15 +18,15 @@ export declare class DeadlineChunker {
18
18
  * EWMA 평활화 계수
19
19
  */
20
20
  private alpha;
21
- constructor(targetMs?: number);
21
+ constructor(startChunkSize?: number, targetMs?: number, alpha?: number);
22
22
  /**
23
23
  * EWMA 평활화 계수를 사용하여 평균 처리 시간을 업데이트합니다.
24
24
  */
25
- _updateEstimate(elapsed: number, count: number): void;
25
+ private updateEstimate;
26
26
  /**
27
27
  * 현재 chunk size를 업데이트합니다.
28
28
  */
29
- _nextChunkSize(): number;
29
+ private nextChunkSize;
30
30
  /**
31
31
  * 주어진 items를 chunk로 분할하여 처리합니다.
32
32
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "document-dataply",
3
- "version": "0.0.10-alpha.8",
3
+ "version": "0.0.11",
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>",
@@ -43,12 +43,12 @@
43
43
  ],
44
44
  "dependencies": {
45
45
  "croner": "^10.0.1",
46
- "dataply": "^0.0.25-alpha.1"
46
+ "dataply": "^0.0.25"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/jest": "^30.0.0",
50
50
  "esbuild": "^0.27.3",
51
- "jest": "^30.2.0",
51
+ "jest": "^30.3.0",
52
52
  "ts-jest": "^29.4.6",
53
53
  "typescript": "^5.9.3"
54
54
  }