Problem/Motivation

When creating content with devel generate module I noticed performance is degraded badly after more and more content is created.

The issue seems related to content that has references to other entities. The Drupal\Core\Field\Plugin\Field\FieldType::generateSampleValue call to getReferenceableEntities without specify a limit of entities. And after creating a lot of nodes (+1000) it start to create Fatal errors.

Proposed resolution

Provide a when calling getReferenceableEntities from generateSampleValue to avoid fatal errors.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dagmar created an issue. See original summary.

dagmar’s picture

Status: Active » Needs review
FileSize
944 bytes
dagmar’s picture

Issue summary: View changes
dagmar’s picture

Issue tags: +Performance, +Default content
Berdir’s picture

Status: Needs review » Needs work

Makes sense to me. This is "just" default content, I don't think we want to test creating 1000 nodes to make sure it doesn't fail.

However, 10 is quite low. It means you will only get references to the same 10 nodes. Can we maybe add a random sort or something like that, or sort by id desc, so we always pick from the last 10 ids?

dagmar’s picture

Status: Needs work » Needs review
FileSize
1.73 KB

Good idea. What about this patch?

Berdir’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/EntityReferenceItem.php
@@ -268,7 +268,26 @@ public function preSave() {
+    // Select a random number of references between the last 50 referenceable
+    // entities created.
+    if ($referenceable = $selection_handler->getReferenceableEntities(NULL, 'CONTAINS', rand(1, 50))) {
       $group = array_rand($referenceable);

we have the random value below, we don't need to fetch a random amount of values as well I think?

dagmar’s picture

Status: Needs work » Needs review
FileSize
1.72 KB

True! Thanks @berdir

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Works for me.

alexpott’s picture

Version: 8.3.x-dev » 8.2.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed b1a178c and pushed to 8.3.x. Thanks!

Setting to patch to be ported for cherry-pick to 8.2.x once 8.2.0 is released.

  • alexpott committed b1a178c on 8.3.x
    Issue #2804595 by dagmar, Berdir: Sample values for entity references...
jibran’s picture

@Berdir do you think we need this for DER as well?

Berdir’s picture

if you have the same logic implemented then yes, I guess so.

alexpott’s picture

Status: Patch (to be ported) » Fixed

Committed 2d63542 and pushed to 8.2.x. Thanks!

  • alexpott committed 2d63542 on 8.2.x
    Issue #2804595 by dagmar, Berdir: Sample values for entity references...

Status: Fixed » Closed (fixed)

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