Hei,

i love the idea and opportunities this module provides. Sadly it's not possible to use it for me.
After enabling the module our local site runs in a timeout (30s) and the memory consumption goes very high so that it goes over 128mb of memory usage.

The site makes heavy use of paragraphs, perhaps this is the problem?

What informations should i provide so that we can debug this issue?

Thanks in advance

Comments

yobottehg created an issue. See original summary.

shadcn’s picture

Hi. So this happens when there’s a circular entity reference. Entity A references entity B and B references A.

We have a fix for this. I haven’t had time to look at it. I’ll see if I can commit it later today

yobottehg’s picture

This could definitely be the problem.

The frontpage has a teaser section for products. Products have a lot of entity reference revision fields which reference a lot of other things. Somewhere inside there will be some loop.

shadcn’s picture

Assigned: Unassigned » shadcn
Priority: Normal » Major

Agreed. This is why we are now making entity reference normalization opt-in. We should have a fix up on the site soon.

(Bumping this to major)

yobottehg’s picture

Something like a |serialize twig filter could work. Or something like the jsonapi_defaults module in which you can specify per resource / content type which things to serialise / include by default.

shadcn’s picture

Version: 8.x-1.x-dev » 8.x-2.x-dev
Status: Active » Needs review

OK I finally got some time today to work on this.

The EntityReferenceFieldItemNormalizer now returns simple values for target_id, target_type..etc which you can now feed to a Twig value() function to get field values back.

Example: (assumes an article node type referencing an author entity type).

Before (8.x-1.x)

{{ _article.field_author.field_job_title }}

After (8.x-2.x)

{{ value(_article.field_author).field_job_title }}

Can you test and let me know what you think? (Note this is in the 8.x-2.x branch)

Thanks

yobottehg’s picture

Thanks, I'll test this on a project i'm working on and let you know the next days.

yobottehg’s picture

So i tested this and it's working!
I got no more out of memory issues and the overall performance is really good.

I have some suggestions and also some patches that i'll upload in different issues.

First:
Currently the value function will always load the original language of the entity and not the translation if there is one.
-> I added the entity repository service and load the translation if it exists. Will provide a patch.

Second:
The entity reference normaliser will also only normalise the values of the original entity and not the translation if there is one.
-> Same as on First

Third:
The DX in handling the multiple entity references is currently suboptimal.

Example here:

{% set medias = [] %}
{% for media in application.field_hero_images %}
  {% set medias = medias|merge([value(media)]) %}
{% endfor %}

-> I added a value_multiple twig function for this use cases.

I will create the follow ups now.

yobottehg’s picture

Status: Needs review » Reviewed & tested by the community
shadcn’s picture

Status: Reviewed & tested by the community » Fixed

@yobottehg Thanks for testing. This is now in the 8.x-2.x branch. We can follow up in the related issues. Really appreciate the help.

Status: Fixed » Closed (fixed)

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