Problem/Motivation
The method does a $bundle_of !== FALSE check. But it actually returns NULL, not FALSE if the bundle does not exist. That results in a $entity_manager->clearCachedFieldDefinitions() call for every node/user/comment that is saved.
Proposed resolution
Thought of different ways to fix this. Quick fix is to remove the type safe check and just do if ($bundle_of), because we're not interested that it is not FALSE that seems like an unnecessary negative. We just want to know if it has a $bundle_of.
However, I think this logic is better off in ConfigEntityBundleBase, where all other bundle_of logic lives too. Refactored the existing postSave() there to cover this part too.
I don't think this needs a regression test, for example by saving a node and checking if the caches were cleared as the problematic code path simply doesn't exist anymore.
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#10 | entity-field-cache-clears-2359509-10-interdiff.txt | 1.13 KB | Berdir |
#10 | entity-field-cache-clears-2359509-10.patch | 7.97 KB | Berdir |
#8 | entity-field-cache-clears-2359509-8-interdiff.txt | 2.69 KB | Berdir |
#8 | entity-field-cache-clears-2359509-8.patch | 8.12 KB | Berdir |
Comments
Comment #1
BerdirHere is a patch.
Comment #3
Wim LeersIf it's technically impossible to create a content entity type that is the bundle entity type for another entity type, then this looks fine.
Comment #4
Wim LeersComment #5
BerdirIt is not technically impossible, but you would have a lot of weird problems (like your fields would depend on the bundle, which would be content, not config). Which we can not safely recover from, which is one of the requirements from the whole config depending on content topic.
In case you do not have a config entity/do not depend on ConfigEntityBundleBase, (it could theoretically be a simple config), then it is the same as for all the other logic that is already in ConfigEntityBundleBase like calling $entity_manager->onBundleDelete() and the other methods: You are responsible to do it manually.
Comment #6
BerdirOh, fun with the cached language list again. Related to #2303877: Remove cached languages from ContentEntityBase.
Implemented it so we can unset on __sleep() and lazy-load.
Comment #7
dawehnerGiven that we need it both times we could just store it as well ...
It feels wrong to hardcode all that special bits inside the base entity class ... but rather we should have a simple event which different code cares about.
+1 do less in the constructor
I don't get why we not just do
now that you have introduce it
Ups
Comment #8
Berdir1. Changed.
2. Not sure I agree but I think it doesn't really matter for this issue :)
3. I'm not sure if it will work, but it is possible that the fix that I'm applying here will also fix why we had to add those checks before.
Comment #10
Berdir3. Yeah, no luck :)
Comment #12
Wim LeersI didn't review the language-related changes in this patch that were imported from #2303877: Remove cached languages from ContentEntityBase, but I did review the key changes in this issue. It basically moves
Entity::onUpdateBundleEntity()
which is called byEntity::invalidateTagsOnSave()
which is called byEntity::postSave()
intoConfigEntityBundleBase::postSave()
.This is okay for the reasons explained in #5.
So: if plach approves the language parts of this patch, then this is RTBC IMHO.
Comment #13
plachIt is :)
Comment #14
alexpottCommitted 9e8a523 and pushed to 8.0.x. Thanks!