-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LimitedCollection's maxSize also counts items that pass keepOverLimit #10062
Comments
That’s what keepOverLimit is documented to be. And that’s what it is. It decides whether to keep an element although it‘s past the maxSize. Nowhere does it say that it doesn’t count towards the maxSize nor was it ever intended to be that way. So I doubt anyone would implement a breaking change into how this property acts without any reason to do so other than you misunderstanding what it‘s supposed to do. |
It's exactly because it doesn't say what happens to maxSize that I think it's reasonable to assume it doesn't count, just like it would be reasonable to assume that it does. If you're keeping an element over the limit, why would it count towards that limit and take up the space that could be taken up by other values that don't pass the requirements of that function? |
Hi guys! In my understanding it is ok like @Qjuh described the handling of the count / maxSize. But I found another strange behaviour here: To me it's strange that the first elements of the collection get cut off in favour of the latest ones, even when they are over limit and not to be kept over limit. Example:
-> Check that the first element is removed and the third one will be inserted. Question: Is that the intended behavior? In the upper scenario I would expect the third item not to be inserted as it over the limit and does not pass the keepOverLimit function. |
* 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
While investigating this issue we discovered some peculiar behaviour of this class. |
That absolutely is intended behavior. A LimitedCollection acts as a FIFO Queue that’s also a Map. So the oldest elements get deleted to make room for new ones. and regarding the other issue I explained in the PR why that‘s not an issue at all. |
Which package is this bug report for?
discord.js
Issue description
The way I interpret this keepOverLimit function is that "any element added that passes this condition isn't counted towards the total size limit". I understand there may be other interpretations to this and that the current implementation may be right in the eyes of who interpreted this criteria, but I think this is also a valid way of seeing it and I would like to know if it is possible to change the current implementation to support this.
Code sample
No response
Versions
Issue priority
Low (slightly annoying)
Which partials do you have configured?
Not applicable
Which gateway intents are you subscribing to?
Not applicable
I have tested this issue on a development release
No response
The text was updated successfully, but these errors were encountered: