The method generateSampleValue() loads all existing referenceable entities, just to check if there are any.
On a large site with many entities, the process will time out or crash the server.
The check is pointless, and should be removed, since the existing entities are not needed at all.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

super_romeo created an issue. See original summary.

super_romeo’s picture

anita_novicell’s picture

I have run in to the same problem.
In my case, I am using layout builder. I go to my content display mode and choose "manage layout". The layout builder will populate the template with sample values. If my content type has a field of the type entity reference revisions, the generateSampleValues() method will be used to do this.
The generateSampleValues() method invokes the getReferenceableEntities() method in Drupal\Core\Entity\Plugin\EntityReferenceSelection\DefaultSelection to check if there are any referenceable entities in the database. However, it is invoked without a limit parameter, so it will attempt to load ALL referenceable entities in the database. If you have a large site with thousands of entities, the process will time out.

The patch provided in comment #2 adds a limit to the method, in order to only load 50 entities. However, the generateSampleValues() method doesn't use existing entities but creates its own dummy entity, so there is actually no need at all for this check nor for loading any existing entities. It should be removed completely, unless the method is changed to actually use existing entities for sample values.
This patch will do that: https://www.drupal.org/files/issues/2019-08-18/2568187-errgen-29.patch
I found it in this issue: https://www.drupal.org/project/entity_reference_revisions/issues/2568187

The foreach is not unlimited, just very large, and it will happen with all entity types, not just paragraphs, so the issue title is misleading and the issue has no description. It took me a long time to even find this issue, and I was just about to create a duplicate.

anita_novicell’s picture

Title: A large number of paragraphs makes generateSampleValue() do unlimited foreach » generateSampleValue() loads ALL existing entities unnecessarily
Issue summary: View changes
Related issues: +#2568187: Improve EntityReferenceRevisionsItem::generateSampleValue to be recursion-safe and devel_generate compatible
FileSize
958 bytes

I have updated the title and description of the issue

azinck’s picture

Status: Needs review » Reviewed & tested by the community

Can confirm this is a problem, and can confirm #4 fixes it for us. Thanks @anita_novicell!

Berdir’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, committed.

  • Berdir committed 0e5277f on 8.x-1.x authored by anita_novicell
    Issue #3084661 by super_romeo, anita_novicell: generateSampleValue()...

Status: Fixed » Closed (fixed)

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