feat: sort source entries before slicing when using max_item_count #1765
+25
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
When using the prop
max_item_count
, there is a known catch (sorting issue) from the doc:This PR makes it so the source entries are sorted before being sliced and fed to the full list of entries and then sorted again.
If the performance hit is too big, we could maybe add an optional boolean option such as
sort_before = true
along withmax_item_count
, to make sure the user still wants this sorting to happen even if it is slower.EDIT:
Just had another thought... We could maybe avoid all this sorting X times per source + 1 time per group index, while still keeping the results accuracy, but it would bring some changes to how the final list is created. I'll try that later and maybe create another PR if it's worth it.
EDIT2:
Sorry for editing this PR once again but the first version felt wrong.
So this time what i did is just moving the whole
max_item_count
handling.We fetch all the entries, we sort them, and at the end, depending on the source of the entry, we filter them out if they reached
max_item_count
.I don't have that much experience with array manipulation in lua but i feel like the second commit would be way better performance-wise than the first one.
Thanks for your time.