@glimt/record 0.0.65 → 0.0.67

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 CHANGED
@@ -10327,6 +10327,56 @@ const _StormSnapshotManager = class _StormSnapshotManager2 {
10327
10327
  __publicField(_StormSnapshotManager, "instance");
10328
10328
  let StormSnapshotManager = _StormSnapshotManager;
10329
10329
  const stormSnapshotManager = new StormSnapshotManager();
10330
+ const _MutationRateLimiter = class _MutationRateLimiter2 {
10331
+ constructor() {
10332
+ __publicField(this, "mutTracker");
10333
+ __publicField(this, "interval", 50);
10334
+ __publicField(this, "limit", 100);
10335
+ __publicField(this, "inGlobalStorm", false);
10336
+ if (_MutationRateLimiter2.instance) {
10337
+ return _MutationRateLimiter2.instance;
10338
+ }
10339
+ _MutationRateLimiter2.instance = this;
10340
+ debugLog(`MutationRateLimiter, init`);
10341
+ this.reset();
10342
+ }
10343
+ reset() {
10344
+ this.mutTracker = {
10345
+ muts: 0,
10346
+ ts: -1
10347
+ };
10348
+ }
10349
+ isStorming(muts) {
10350
+ const now = Date.now();
10351
+ if (this.inGlobalStorm) {
10352
+ if (now - this.mutTracker.ts > this.interval) {
10353
+ this.inGlobalStorm = false;
10354
+ debugLog(`MutationRateLimiter, detected global storm over`);
10355
+ return false;
10356
+ }
10357
+ this.mutTracker.ts = now;
10358
+ return true;
10359
+ }
10360
+ if (this.mutTracker.ts === -1) {
10361
+ this.mutTracker.muts = muts;
10362
+ } else {
10363
+ if (now - this.mutTracker.ts <= this.interval) {
10364
+ this.mutTracker.muts += muts;
10365
+ if (this.mutTracker.muts >= this.limit) {
10366
+ this.inGlobalStorm = true;
10367
+ this.reset();
10368
+ debugLog(`MutationRateLimiter, detected global rolling storm`);
10369
+ return true;
10370
+ }
10371
+ }
10372
+ }
10373
+ this.mutTracker.ts = now;
10374
+ return false;
10375
+ }
10376
+ };
10377
+ __publicField(_MutationRateLimiter, "instance");
10378
+ let MutationRateLimiter = _MutationRateLimiter;
10379
+ const mutationRateLimiter = new MutationRateLimiter();
10330
10380
  function isNodeInLinkedList(n2) {
10331
10381
  return "__ln" in n2;
10332
10382
  }
@@ -10463,12 +10513,7 @@ class MutationBuffer {
10463
10513
  mutationLimit: 800
10464
10514
  //was 1500
10465
10515
  });
10466
- __publicField(this, "rollingMutTracker", {
10467
- accumlativeMuts: 0,
10468
- ts: -1,
10469
- interval: 50
10470
- });
10471
- __publicField(this, "handleStormMutations", (muts) => {
10516
+ __publicField(this, "handleStormMutations", (muts, canFinishStorm = true) => {
10472
10517
  const time = Date.now();
10473
10518
  if (this.stormInfo == null) {
10474
10519
  debugLog(
@@ -10494,7 +10539,7 @@ class MutationBuffer {
10494
10539
  });
10495
10540
  }
10496
10541
  clearTimeout(this.stormInfo.timeout);
10497
- if (muts.length < this.stormSettings.batchSize) {
10542
+ if (canFinishStorm && muts.length < this.stormSettings.batchSize) {
10498
10543
  this.handleStormFinish();
10499
10544
  } else {
10500
10545
  this.stormInfo.timeout = setTimeout(
@@ -10533,34 +10578,15 @@ class MutationBuffer {
10533
10578
  }
10534
10579
  });
10535
10580
  __publicField(this, "processInternalMutations", (muts, overrideStorm = false) => {
10536
- console.log(
10537
- "muts",
10538
- muts.length,
10539
- JSON.parse(JSON.stringify(this.rollingMutTracker))
10540
- );
10541
10581
  if (!overrideStorm) {
10582
+ const isStorming = mutationRateLimiter.isStorming(muts.length);
10583
+ if (isStorming) {
10584
+ this.handleStormMutations(muts, false);
10585
+ return;
10586
+ }
10542
10587
  if (this.stormInfo != null || muts.length >= this.stormSettings.batchSize) {
10543
10588
  this.handleStormMutations(muts);
10544
10589
  }
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
10590
  return;
10565
10591
  }
10566
10592
  for (const mut of muts) {