1

Background

Normally when an entity is loaded in D7, the 'field_attach_load' step will load all the data from fields into the entity object.

The field_sql_storage_field_storage_load() loads the data from all columns by default.

On a page with a view, this could happen for many entities.

Use case

We want to create a field to be used for very long html.

This content should only be loaded on specific pages where this html is actually being displayed.

Problem

We want to avoid the big html from being loaded into memory in the field_attach_load step, to avoid memory problems.

Solutions considered so far

I think we would need a custom field type with its own loading logic. I have not found any contrib solutions yet.

The obstacle seems to be the default field_attach_load logic, which always loads all the columns from the field table. I don't see a way around that.

We could store the data in a separate table, but this would need babysitting to keep the extra table in sync with the field table.

7
  • Have you come across hook_field_storage_load()? I haven't checked very far down but it feels like you could put your custom logic in there
    – Clive
    Commented Jan 20, 2021 at 15:38
  • This hook is implemented by the field storage engine - see field_sql_storage_field_storage_load(). So I would have to write an additional storage engine and only use it for specific fields. I don't even know if this is possible..
    – donquixote
    Commented Jan 20, 2021 at 15:48
  • 1
    Yep that sounds right, it's a thread to pull at though
    – Clive
    Commented Jan 20, 2021 at 15:58
  • 1
    Independently from the Drupal version specific implementation you could use a separate entity instead of a separate table. This could be Paragraphs because of the inline editing it provides and it works with revision if you need this.
    – 4uk4
    Commented Jan 20, 2021 at 19:42
  • @4k4 Paragraphs would work, yes. It would have an overhead for editor UX because they need to click "Add paragraph" before they can start editing. But this could be surivable. And I think the paragraph is only loaded when it needs to be displayed, not immediately when loading the host entity.
    – donquixote
    Commented Jan 20, 2021 at 20:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.