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
Comment #2
chriscalip commentedComment #3
chriscalip commentedComment #8
chriscalip commentedComment #9
chriscalip commentedComment #11
ndobromirov commentedFrom 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?
Comment #12
hchonovThe 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.
Comment #17
ebeyrent commentedI 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?