[BUGS-7148] Handle duplicate keys in get_multiple function#448
Merged
jazzsequence merged 4 commits intopantheon-systems:mainfrom Nov 21, 2023
Merged
Conversation
Signed-off-by: Souptik Datta <[email protected]>
Contributor
Author
|
Hi @jazzsequence any thoughts or suggestion on this one? |
get_multiple functionget_multiple function
Member
|
Thanks for the PR! Love to see a PR with tests 🎊. Tracking this internally as |
Contributor
Author
|
Thank you! 😃 🙇 |
jazzsequence
approved these changes
Nov 21, 2023
Contributor
|
Merging this. We'll get this in the next release, likely sometime next week. Thanks @Souptik2001 |
Contributor
Author
|
Thanks @jazzsequence! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 👋 ,
Seems like the
WP_Object_Cache:get_multiplefunction breaks when we pass duplicate keys in the$keysarray argument.When any duplicate key is passed in the array all the values of the keys coming after that duplicate gets messed up. Basically they gets shifted by one after a duplicate. Again after another duplicate is there the values after that second duplicate gets shifted by two, and similarly.
This basically happens due to the way we get the cache values from the two arrays -
$remaining_keysand$results. In the results array we don't get the value twice, we just get once. But we iterate through all the$remaining_keysand just access the corresponding index of the$resultsarray. That's why this is happening.So, the easiest solution for this would be to just fetch the unique values in the beginning of the function only. This will not only fix the bug, but also reduce the minor redundant extra computations of the duplicate keys.
I have also added a test case, which will break if you run it by removing the fix from the
object-cache.php.I think this edge case should be handled here, because this function doesn't deny you to pass duplicate keys, but also doesn't handle duplicate keys.
Thanks! Please let me know if any other info is needed. 🙂