The \Drupal\search_api\Item\Item class (like others) has a __toString() method that allows developers to easily see the contents of an item for debugging purposes. (A usage facing end users doesn’t seem reasonable, I’d say.)
This string representation also includes the item’s fields, but instead of only printing those that are currently part of the item object (as would seem reasonable and expected, at least in my opinion) we do $this->getFields(), which extracts all the item’s fields to print them. The code suggests that this is merely by accident, too. In any case, while the performance cost doesn’t really seem relevant in the case of a DX feature that won’t be used in production anyways, I don’t think anyone expects a __toString() method with side effects, but to just have the item printed in its current form. (Explicitly extracting the field values beforehand, if needed, is the matter of a single method call.)
So, I propose changing those calls to $this->getFields(FALSE).
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | no-extract-3059070.patch | 614 bytes | fconnolly |
Comments
Comment #2
borisson_100% agree. Should be an easy fix (since it's just changing that method call). Tagging as novice.
Comment #3
fconnolly commentedComment #4
fconnolly commentedComment #5
borisson_Yes, this looks like what we needed from this issue, thanks!
Comment #7
drunken monkeyYes, looks good! Thanks for providing the patch!
Committed.
And a round of cheap contrib credits for everyone! \o/ ;)