Problem/Motivation
I've noticed that ContentEntityBase::getTranslatedField is called recursively for non translatable fields and also in __sleep the field values of non translatable fields will be stored twice and the function getValue will be called for all the translations for which a field has been initialized. Also if you iterate over $values you will get unneeded iterations over the same values. In the case where the an referenced entity of a non translatable field will be returned by FieldItemList::getValue this would cause $values to contain the referenced entity not only once but one time for the default langcode and additionally so many times as the number of entity translations, which in case of serializing the parent would cause a bigger serialized object.
Proposed resolution
Remove the recursive call of ContentEntityBase::getTranslatedField and store directly non translatable fields only under the default langcode by keeping track which field are translatable and which not.
Remaining tasks
Reroll
Tests (maybe)
Review.
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#26 | 2828133-26.patch | 6.91 KB | Abhisheksingh27 |
#5 | interdiff-4-5.txt | 984 bytes | hchonov |
#5 | 2828133-5.patch | 4.7 KB | hchonov |
#4 | interdiff-2-4.txt | 773 bytes | hchonov |
#4 | 2828133-4.patch | 4.59 KB | hchonov |
Comments
Comment #2
hchonovComment #4
hchonovSo the problem that has been hidden until now is that if we have already initialized a field but afterwards have removed an entity translation and we try to get the field through ContentEntityBase::get we will get the field but if we try getting the field through ContentEntityBase::getTranslatedField there will be an exception for accessing a field of a removed translation ... This is what happens now when deleting an entity translation for the user entity where the name field is not translatable and not any more accessible with the changes in ContentEntityBase::getTranslatedField from ContentEntityBase::get by the following code :
because non translatable fields will not be kept anymore under the langcode for which they have been requested.
But this however deserves its own issue and for now I am only making changes in ContentEntityBase::get to replicate the current behavior.
Comment #5
hchonovA little bit faster check for non translatable field in ContentEntityBase::get is also possible.
Comment #6
hchonovComment #8
vijaycs85Thanks for working on this @hchonov. I found it it's quite complex fix. It would be nice to have a test to cover this change (i.e. just test to fail and with this patch to pass). Also if we are looking at perf angle, would be nice to have xprofile.
Looks like a complicated check. can we split this as separate helper? also a comment to say what are we checking here.
Comment #9
hchonovHmm this is just code refactoring and there is no test that will fail. The code as it is now is correct but it is using unnecessary recursion which means one more function call put on the call stack and avoiding it just simply implies a better code flow. I do not think that we need any profiling.
Comment #11
hchonovComment #12
maacl CreditAttribution: maacl commented@hchonov is there an issue for the case you described in #4? I'm having exactly this, I cannot delete a translation of a node because of the exception beeing thrown. ("The entity object refers to a removed translation (en) and cannot be manipulated")
Comment #13
hchonov@maacl , I am not aware of such an issue. I think the problem here was caused by some of my changes in the patch.
Comment #25
smustgrave CreditAttribution: smustgrave at Mobomo commentedThis issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.
Updated the IS remaining tasks field
Reading the comments, specifically #4, this seems like it could be a bug and that we will need a test case showing the issue.
Comment #26
Abhisheksingh27 CreditAttribution: Abhisheksingh27 at OpenSense Labs for DrupalFit commentedAdding reroll for 10.1.x