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.

Comments

Berdir created an issue. See original summary.

arpad.rozsa’s picture

Status: Active » Needs review
StatusFileSize
new3.16 KB

Created 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.

berdir’s picture

Status: Needs review » Reviewed & tested by the community

Nice, looks good to me.

miro_dietiker’s picture

Committed for more speed! :-D

berdir’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.