Per developer thread :
How load only some node fields?
http://drupal.stackexchange.com/questions/199268/how-load-only-some-node...

An entity load or node_load is too slow and memory intensive. For long running batch operations node api is unusable.

Quote :
Why do think it violates anything? I'm trying to work around performance issues. It doesn't make sense to load 100 fully blown node objects just check values of one field for each of those nodes. And I do want to use API for that. If I wouldn't, I would write SQL queries to get that data, but that defeats the purpose of using drupal in the first place.
Quote :
Unfortunately what you want doesn't exist in the API @SiliconMind, I just spent a little bit checking. All field data is loaded in bulk via ContentEntityStorageBase::doLoadRevisionFieldItems, and the standard SqlContentEntityStorage doesn't contain any methods for extracting individual fields. If you haven't already done so, it might be worth benchmarking this to see if there's a real problem. A lot of work was done on the cache system for D8, things might not be as slow as you think

Lets provide relief to D8 Devs by providing this important DX api.

Comments

chriscalip created an issue. See original summary.

chriscalip’s picture

Title: Bring back field_attach_load » Bring back field.attach.inc
chriscalip’s picture

Title: Bring back field.attach.inc » Bring back field.attach.inc faster node ops (loads,saves) for partial doing.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

chriscalip’s picture

Title: Bring back field.attach.inc faster node ops (loads,saves) for partial doing. » Bring back partial entity CRUD!
chriscalip’s picture

Title: Bring back partial entity CRUD! » Bring Back Partial Entity CRUD API

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ndobromirov’s picture

From what I know this will affect revisions support to a very big extent.
Making partial changes to entities might make revisions management overly complex :(.

Anyone with more know-how could add more?

hchonov’s picture

The issue summary is only about loading field values, not about writing them. But even that is not possible without a lot of changes. One of the reasons is that when creating a field instance you need to pass the parent to it - which is the entity object. This means that if you want to load only some of the fields, then we'll have to create some fake entity object to provide to the field as parent. Additionally we'll have to implement lazy loading for field values or throw an exception on accessing not loaded fields.
Altogether this is a pretty complex change.

On the other side I see an entity object as a whole structured piece and during entity CRUD operations, especially on save during the creation of a new revision, all the field values are required.

It would be very helpful to provide more information about the use case.

Please note that once an entity is loaded it will be put in the persistent entity cache and any subsequent loads will be faster than the initial one. This means that any subsequent entity loads will be almost as fast as loading a single field, because we have to load only one entry from a single database table. The only disadvantage is that more data will be transferred from the database in case only a single field is required.

However if we have entity cache HIT, then we'll have all the fields at once. If we want to load only some specific fields, then we will have to read field data from multiple tables. If we want to optimize that we'll have to introduce a cache based on the combination of fields being retrieved. Not having such cache means that if you load the same combination of fields multiple times in a row then the data retrieval will be slower than loading the whole cached entity.

Having said all this I would personally prefer not to implement partial entity load.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ebeyrent’s picture

I would point out that with jsonapi, we can do partial loads of entities. So, it seems like it can already be done on some level?

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.