From 2c670685d801878d18084a0a152c95781c312810 Mon Sep 17 00:00:00 2001 From: Pablo Thomas Date: Wed, 7 Feb 2024 15:02:56 +0100 Subject: [PATCH] fix(LimitedCollection): fix keepOverLimit behavior #10062 * always allow updating of elements even when maxSize is 0 * keep elements in the collection and disallow adding new ones if non matching the keepOverLimit expression * do not remove any non-matching element from the collection when a new one is tried to add --- packages/discord.js/src/util/LimitedCollection.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/discord.js/src/util/LimitedCollection.js b/packages/discord.js/src/util/LimitedCollection.js index 12a8360a1934..5a0eb54029a5 100644 --- a/packages/discord.js/src/util/LimitedCollection.js +++ b/packages/discord.js/src/util/LimitedCollection.js @@ -47,14 +47,10 @@ class LimitedCollection extends Collection { } set(key, value) { - if (this.maxSize === 0 && !this.keepOverLimit?.(value, key, this)) return this; if (this.size >= this.maxSize && !this.has(key)) { - for (const [k, v] of this.entries()) { - const keep = this.keepOverLimit?.(v, k, this) ?? false; - if (!keep) { - this.delete(k); - break; - } + const keep = this.keepOverLimit?.(value, key, this) ?? false; + if (!keep) { + return this; } } return super.set(key, value);