@glimt/record 0.0.65 → 0.0.66
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/record.cjs +50 -21
- package/dist/record.cjs.map +1 -1
- package/dist/record.js +50 -21
- package/dist/record.js.map +1 -1
- package/dist/record.umd.cjs +50 -21
- package/dist/record.umd.cjs.map +2 -2
- package/dist/record.umd.min.cjs +23 -23
- package/dist/record.umd.min.cjs.map +3 -3
- package/package.json +1 -1
package/dist/record.cjs
CHANGED
|
@@ -10327,6 +10327,49 @@ const _StormSnapshotManager = class _StormSnapshotManager2 {
|
|
|
10327
10327
|
__publicField(_StormSnapshotManager, "instance");
|
|
10328
10328
|
let StormSnapshotManager = _StormSnapshotManager;
|
|
10329
10329
|
const stormSnapshotManager = new StormSnapshotManager();
|
|
10330
|
+
class MutationRateLimiter {
|
|
10331
|
+
constructor() {
|
|
10332
|
+
__publicField(this, "mutTracker");
|
|
10333
|
+
__publicField(this, "interval", 50);
|
|
10334
|
+
__publicField(this, "limit", 150);
|
|
10335
|
+
__publicField(this, "inGlobalStorm", false);
|
|
10336
|
+
debugLog(`MutationRateLimiter, init`);
|
|
10337
|
+
this.reset();
|
|
10338
|
+
}
|
|
10339
|
+
reset() {
|
|
10340
|
+
this.mutTracker = {
|
|
10341
|
+
muts: 0,
|
|
10342
|
+
ts: -1
|
|
10343
|
+
};
|
|
10344
|
+
}
|
|
10345
|
+
isStorming(muts) {
|
|
10346
|
+
const now = Date.now();
|
|
10347
|
+
if (this.inGlobalStorm) {
|
|
10348
|
+
if (now - this.mutTracker.ts > this.interval) {
|
|
10349
|
+
this.inGlobalStorm = false;
|
|
10350
|
+
debugLog(`MutationRateLimiter, detected global storm over`);
|
|
10351
|
+
return false;
|
|
10352
|
+
}
|
|
10353
|
+
return true;
|
|
10354
|
+
}
|
|
10355
|
+
if (this.mutTracker.ts === -1) {
|
|
10356
|
+
this.mutTracker.muts = muts;
|
|
10357
|
+
} else {
|
|
10358
|
+
if (now - this.mutTracker.ts <= this.interval) {
|
|
10359
|
+
this.mutTracker.muts += muts;
|
|
10360
|
+
if (this.mutTracker.muts >= this.limit) {
|
|
10361
|
+
this.inGlobalStorm = true;
|
|
10362
|
+
this.reset();
|
|
10363
|
+
debugLog(`MutationRateLimiter, detected global rolling storm`);
|
|
10364
|
+
return true;
|
|
10365
|
+
}
|
|
10366
|
+
}
|
|
10367
|
+
}
|
|
10368
|
+
this.mutTracker.ts = now;
|
|
10369
|
+
return false;
|
|
10370
|
+
}
|
|
10371
|
+
}
|
|
10372
|
+
const mutationRateLimiter = new MutationRateLimiter();
|
|
10330
10373
|
function isNodeInLinkedList(n2) {
|
|
10331
10374
|
return "__ln" in n2;
|
|
10332
10375
|
}
|
|
@@ -10468,7 +10511,7 @@ class MutationBuffer {
|
|
|
10468
10511
|
ts: -1,
|
|
10469
10512
|
interval: 50
|
|
10470
10513
|
});
|
|
10471
|
-
__publicField(this, "handleStormMutations", (muts) => {
|
|
10514
|
+
__publicField(this, "handleStormMutations", (muts, canFinishStorm = true) => {
|
|
10472
10515
|
const time = Date.now();
|
|
10473
10516
|
if (this.stormInfo == null) {
|
|
10474
10517
|
debugLog(
|
|
@@ -10494,7 +10537,7 @@ class MutationBuffer {
|
|
|
10494
10537
|
});
|
|
10495
10538
|
}
|
|
10496
10539
|
clearTimeout(this.stormInfo.timeout);
|
|
10497
|
-
if (muts.length < this.stormSettings.batchSize) {
|
|
10540
|
+
if (canFinishStorm && muts.length < this.stormSettings.batchSize) {
|
|
10498
10541
|
this.handleStormFinish();
|
|
10499
10542
|
} else {
|
|
10500
10543
|
this.stormInfo.timeout = setTimeout(
|
|
@@ -10539,28 +10582,14 @@ class MutationBuffer {
|
|
|
10539
10582
|
JSON.parse(JSON.stringify(this.rollingMutTracker))
|
|
10540
10583
|
);
|
|
10541
10584
|
if (!overrideStorm) {
|
|
10585
|
+
const isStorming = mutationRateLimiter.isStorming(muts.length);
|
|
10586
|
+
if (isStorming) {
|
|
10587
|
+
this.handleStormMutations(muts, false);
|
|
10588
|
+
return;
|
|
10589
|
+
}
|
|
10542
10590
|
if (this.stormInfo != null || muts.length >= this.stormSettings.batchSize) {
|
|
10543
10591
|
this.handleStormMutations(muts);
|
|
10544
10592
|
}
|
|
10545
|
-
if (this.stormInfo == null) {
|
|
10546
|
-
const now = Date.now();
|
|
10547
|
-
if (this.rollingMutTracker.ts === -1) {
|
|
10548
|
-
this.rollingMutTracker.accumlativeMuts = muts.length;
|
|
10549
|
-
} else {
|
|
10550
|
-
if (now - this.rollingMutTracker.ts <= this.rollingMutTracker.interval) {
|
|
10551
|
-
this.rollingMutTracker.accumlativeMuts += muts.length;
|
|
10552
|
-
if (this.rollingMutTracker.accumlativeMuts >= this.stormSettings.batchSize) {
|
|
10553
|
-
debugLog(`Mutation storm through rolling detected.`);
|
|
10554
|
-
this.handleStormMutations(muts);
|
|
10555
|
-
this.rollingMutTracker.accumlativeMuts = 0;
|
|
10556
|
-
this.rollingMutTracker.ts = -1;
|
|
10557
|
-
}
|
|
10558
|
-
} else {
|
|
10559
|
-
this.rollingMutTracker.accumlativeMuts = 0;
|
|
10560
|
-
}
|
|
10561
|
-
}
|
|
10562
|
-
this.rollingMutTracker.ts = now;
|
|
10563
|
-
}
|
|
10564
10593
|
return;
|
|
10565
10594
|
}
|
|
10566
10595
|
for (const mut of muts) {
|