@cendarsoss/pusher-js 8.4.17 → 8.4.18

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.
@@ -4,6 +4,7 @@ const base64 = require("@stablelib/base64");
4
4
  const fayeWebsocket = require("faye-websocket");
5
5
  const xmlhttprequest = require("xmlhttprequest");
6
6
  const crypto = require("crypto");
7
+ const lruCache = require("lru-cache");
7
8
  const fossilDelta = require("fossil-delta");
8
9
  const vcdiffDecoder = require("@ably/vcdiff-decoder");
9
10
  function encode(s) {
@@ -3545,12 +3546,15 @@ class UserFacade extends Dispatcher {
3545
3546
  this._signinDoneResolve = resolve;
3546
3547
  }
3547
3548
  }
3549
+ const MAX_CONFLATION_CACHE_KEYS = 2e3;
3548
3550
  class ChannelState {
3549
3551
  constructor(channelName) {
3550
3552
  this.channelName = channelName;
3551
3553
  this.conflationKey = null;
3552
3554
  this.maxMessagesPerKey = 30;
3553
- this.conflationCaches = /* @__PURE__ */ new Map();
3555
+ this.conflationCaches = new lruCache.LRUCache({
3556
+ max: MAX_CONFLATION_CACHE_KEYS
3557
+ });
3554
3558
  this.baseMessage = null;
3555
3559
  this.baseSequence = null;
3556
3560
  this.lastSequence = null;
@@ -3591,7 +3595,7 @@ class ChannelState {
3591
3595
  return this.baseMessage;
3592
3596
  }
3593
3597
  const key = conflationKeyValue || "";
3594
- const cache = this.conflationCaches.get(key);
3598
+ const cache = this.conflationCaches.peek(key);
3595
3599
  if (!cache || baseIndex === void 0) {
3596
3600
  console.error("[ChannelState] No cache or baseIndex undefined", {
3597
3601
  hasCache: !!cache,
@@ -3611,6 +3615,7 @@ class ChannelState {
3611
3615
  });
3612
3616
  return null;
3613
3617
  }
3618
+ this.conflationCaches.get(key);
3614
3619
  return message.content;
3615
3620
  }
3616
3621
  /**
@@ -3618,10 +3623,9 @@ class ChannelState {
3618
3623
  */
3619
3624
  updateConflationCache(conflationKeyValue, message, sequence) {
3620
3625
  const key = conflationKeyValue || "";
3621
- let cache = this.conflationCaches.get(key);
3626
+ let cache = this.conflationCaches.peek(key);
3622
3627
  if (!cache) {
3623
3628
  cache = [];
3624
- this.conflationCaches.set(key, cache);
3625
3629
  }
3626
3630
  if (cache.length > 0) {
3627
3631
  const lastCacheItem = cache[cache.length - 1];
@@ -3633,6 +3637,7 @@ class ChannelState {
3633
3637
  while (cache.length > this.maxMessagesPerKey) {
3634
3638
  cache.shift();
3635
3639
  }
3640
+ this.conflationCaches.set(key, cache);
3636
3641
  }
3637
3642
  /**
3638
3643
  * Check if we have a valid base