Why are document and media relationships, managed directy in the Persist methods and not via notifications ? #17021
Replies: 3 comments
-
I dont have the concrete answer to this, but I would expect it is because relations are considered too important to be executed outside of the transaction. As far as I can see with the current implementation, the content operation will be rolled back if something happens while updating the relations. |
Beta Was this translation helpful? Give feedback.
-
I am not sure they can 100% be relied on as it stands? If a bit of content is added that has references to content that has not yet being added the relations fail. (and this is sort of inevitable when adding bulk content, for example the homepage of the start kit links to products and blogs, and products and blogs are children of the homepage, so it's not possible for those pages to exist first.) if there was a way to fire a refresh of relations after content that situation could be resolved? it does look like the |
Beta Was this translation helpful? Give feedback.
-
In such cases, when storing a reference and the opposing ID does not exist, a notification with corresponding values is a solution to the problem. The consumers who have subscribed to this notification can react with their own logic to resolve the arising inconsistency. |
Beta Was this translation helpful? Give feedback.
-
It's been there for a while now, but when Umbraco is building the relationships for linked document and media, it does so directly in the PersitNew ,. PersisteUpdate methods of the repository ( https://github.com/umbraco/Umbraco-CMS/blob/contrib/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/DocumentRepository.cs#L1051)
the persistRelations method seems independent of the repositories it is in
So, I am not sure why it is baked in this way?
It seems to me that this would make sense being handled as a notification, so after a save/publish/move etc is fired something else managed the relations?
Eoing this directly in the persist method raises some (annoying but not critical) issues. especially when importing content from somewhere else.
For Example, if you try and save a bit of content that has a relationship to another bit of content, but that bit of content doesn't exist yet, you get a warning/log message, and the relationship isn't created.
On a bulk import you can't guarantee that the referenced content exists because it could be a child of the bit of content you are imported (e.g. if you have a content picker on the homepage, picking a child item).
but when you bulk import you can delay notifications, so you can import all the content then have the notifications fire, if this was a notification handler, then it would all 'work'?
Also, because it's a hidden away like so there isn't a 'rebuild/generate relationships' method anywhere that can be called to fix/check/validate these links ?
Beta Was this translation helpful? Give feedback.
All reactions