Problem/Motivation

In InlineEntityFormBase::prepareFormState(), each entity is loaded separately in the foreach loop.
With a lot of items and a slow distant storage backend, this can lead to bad performances.

Proposed resolution

referencedEntities() should be used to load every entity in a single query.

Remaining tasks

I will submit a patch.

CommentFileSizeAuthor
#2 inline_entity_form-3192349-2.patch1.55 KBprudloff

Comments

prudloff created an issue. See original summary.

prudloff’s picture

Status: Active » Needs review
StatusFileSize
new1.55 KB

The attached patch uses referencedEntities(), which loads the entities in a single loadMultiple() query.

joachim’s picture

Status: Needs review » Needs work

Good catch!

Patch looks good, just one question:

+++ b/src/Plugin/Field/FieldWidget/InlineEntityFormBase.php
@@ -359,21 +359,17 @@ abstract class InlineEntityFormBase extends WidgetBase implements ContainerFacto
-        // The $entity can be NULL if the reference is broken.

We've lost the check for broken entities.

Does referencedEntities() do that for us?

prudloff’s picture

referencedEntities() seems to silently ignore invalid target IDs (at least with an SQL storage : SqlContentEntityStorage::doLoadMultiple() uses an IN condition that simply returns nothing for invalid IDs).

joachim’s picture

Status: Needs work » Reviewed & tested by the community

Ok, thanks for looking into that.
In that case, this is ready!

geek-merlin’s picture

LGTM too!

  • geek-merlin committed 0c9fc28 on 8.x-1.x
    Issue #3192349 by prudloff, joachim, geek-merlin: Load every referenced...
geek-merlin’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed. Thanks a bunch!

Status: Fixed » Closed (fixed)

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