Problem/Motivation
KeyValueStoreInterface provides a different set of methods to access to the values stored there.
However, for large collections with a big number of items, the getAll() method can be problematic and cause memory issues.
To mitigate this, an option would be to get a list of item ids in the collection, and use chunks or batch API to process all of them.
To allow this, we would need a getAllKeys() method.
Proposed resolution
Add a new method getAllKeys() to Drupal\Core\KeyValueStore\KeyValueStoreInterface.
Remaining tasks
Add new method and tests.
User interface changes
N/A
Introduced terminology
N/A
API changes
Add a new method getAllKeys() to Drupal\Core\KeyValueStore\KeyValueStoreInterface.
Data model changes
Release notes snippet
| Comment | File | Size | Author |
|---|
Issue fork drupal-3563639
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
plopescComment #4
plopescMoving to NR.
This new method would be helpful for scenarios like the one described in #3542436: Cleanup key_value table.
Comment #5
plopescComment #6
smustgrave commentedCan we get a change record for it please.
Comment #7
plopescChange record draft added. Thank you for the heads-up!
Comment #8
smustgrave commentedCR reads fine to me
Seems like a straight forward addition no comment.
Comment #9
ghost of drupal pastThanks for the idea. I have two concerns here:
array|\Traversableinstead ofarrayComment #10
nicxvan commentedI'm going to set to needs work for 9.
9.1 is correct.
9.2 I agree.
Comment #11
plopescThank you for your review!
Added return type hinting. Used
iterableinstead ofarray|\Traversable. From what I read, it is equivalent.Comment #12
ghost of drupal pastAh yes, thanks, sorry I forgot they fixed the iterable issues in PHP 8.2.0, all good.
Comment #13
smustgrave commentedFeedback appears to be addressed.
Comment #15
catchAdding a method to an interface is allowed per https://www.drupal.org/about/core/policies/core-change-policies/bc-polic...
However, I think we should check contrib to see if there are actual implementations around, and probably open issues against those modules if so.
Comment #16
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #17
smustgrave commentedBot rebellion
Comment #18
catchMoving to needs review for #15.
Comment #19
plopescMade some searches in https://search.tresbien.tech/ and found some possible usages where all the items were loaded, but only the keys were used:
https://git.drupalcode.org/project/canvas/-/blob/1.x/src/ComponentIncomp...
https://git.drupalcode.org/project/project_browser/-/blob/2119816e37927d...
Also found a place in core where we could take advantage of this new method:
https://git.drupalcode.org/project/drupal/-/blob/9fc3187d7cc206c9101a22b...
Comment #20
plopescBack to NR, once this gets merged, we could open issues in contrib modules above to let them know that they could use the new function.
Comment #21
needs-review-queue-bot commentedThe Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #22
smustgrave commentedbelieve the bot got this one wrong.