I noticed that in ParagraphsType::getFileByUuid(), we do a uuid-based entity load, which is usually quite slow. And we're doing that multiple times for the same paragraph type (I think each displayed paragraph + the modal add form).
I saw 76 queries from that method on a page with 15 or so paragraphs.
Lets cache this.
See how we did that in core for block_content with \Drupal\block_content\BlockContentUuidLookup, see usage in \Drupal\block_content\Plugin\Block\BlockContentBlock.
It's a cache collector, so over time as we request it, we will populate the persistent and static cache in that service.
We do need to check invalidation, we could *maybe* just rely on the paragraphs_type_list cache tag, but not sure if that will already be resolved in time for the calls in ParagraphsType::postSave(), we could also explicitly invalidate it there.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | optimize_paragraphs_type_getfilebyuuid-3016615-2.patch | 3.16 KB | arpad.rozsa |
Comments
Comment #2
arpad.rozsa commentedCreated a cache collector as you suggested, which caches the file ids by the uuids and changed the ParagraphsType::getFileByUuid() method's logic to load the file from this cache.
Comment #3
berdirNice, looks good to me.
Comment #5
miro_dietikerCommitted for more speed! :-D
Comment #6
berdir