Empty field leads to full entity load

Created on 29 October 2020, over 4 years ago
Updated 18 March 2025, about 2 months ago

Problem/Motivation

In the WissKI system our data backend has huge amounts of information and it is very costly to load the entity, so I would like to avoid it at all costs. However when an entity gets indexed and a particular field is not filled with data the index does not contain an empty array but it contains simply nothing. This leads to search api doing a full load of the entity because it can not detect the dependency as loaded - see:
/search_api/src/Plugin/views/field/SearchApiFieldTrait.php ~around Line 567

foreach ($dependents as $dependent) {
if (!isset($row->$dependent)) {
$required = TRUE;
...

Steps to reproduce

Index some fields of an entity, fill the fields on some entities and on some not, index that and display that in a view.

Proposed resolution

Either we must store an empty array for an indexed value that was empty or we need to check for empty fields otherwise.

Remaining tasks

Feature request
Status

Needs work

Version

4.0

Component

Code

Created by

🇩🇪Germany Knurg

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand ericgsmith

    I'm having a different issue but it feels very related to this as the issue stems from the behaviour for empty fields.

    In my case the field is a property added by a processor - I'm not sure if that fits in the definition here of a field.

    In my case, I have "Retrieve result data from Solr" set to true and I am using the search api attachments module to index document contents. I am using that field in views.

    When the field is empty I can see the same outcome as the issue summary when the field is pre rendered - !isset($row->$dependent)) is TRUE so the field becomes required. Rather than loading the entity, this now diverges from the issue summary and loads the processor as calls addFieldValues.

    I have tried using the "Index empty full fields" option but when it comes to indexing it gets to the loop where values are added - but at this point $values is an empty array so nothing is added to the index.

    Applying this patch seems to resolve the issue - the empty field is added to the result set and then when the check is done in the getValuesToExtract the value set is an empty array and no action is taken.

    I will do a more thorough test & review in the next few days.

  • 🇳🇿New Zealand ericgsmith

    ericgsmith changed the visibility of the branch 3179643-empty-field-entity-load to hidden.

  • 🇳🇿New Zealand ericgsmith

    ericgsmith changed the visibility of the branch 8.x-1.x to hidden.

  • 🇳🇿New Zealand ericgsmith

    ericgsmith changed the visibility of the branch 3179643-empty-field-leads to hidden.

  • Pipeline finished with Failed
    about 2 months ago
    Total: 132s
    #451559
  • 🇳🇿New Zealand ericgsmith

    Added a check to cover the remaining check that the field was requested mentioned in #9

    I haven't moved this to Github yet - I think getting buy in for the approach first since this has been open for a while.

    While I think conceptually "Index empty fields" is probably a more logical thing to opt in to, this looked to have a few moving parts I didn't understanding while debugging.

Production build 0.71.5 2024