Optimize saving relational fields #16210
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changes in this pull request
Every time when relational field is changed Pimcore always delete all relations related to the field
pimcore/models/DataObject/Concrete/Dao.php
Lines 235 to 239 in dd81ef4
If relational field have a lot of relations this behavior may take time to firstly delete all relations and then insert it again.
This PR changed standard behavior and relations will be deleted only if it's really been deleted but not all relations. And only new relations will be inserted.
Additional info
WHAT
馃 Generated by Copilot at 76a0928
This pull request makes several formatting, readability, and performance changes to various PHP files in the pimcore/pimcore repository. It adds empty lines to the end of some files and removes redundant comment lines from others to comply with the PSR-12 coding standard and improve code quality. It also improves the logic for deleting relational objects from the database when updating a data object to avoid unnecessary queries and errors.
馃 Generated by Copilot at 76a0928
HOW
馃 Generated by Copilot at 76a0928
generateCodes
inPattern
andwriteSaveQueue
inCoreCacheHandler
to improve code readability and quality (link, link)Service
to avoid confusion (link)save
inAbstractRelations
to avoid unnecessary database queries and errors when saving empty relations (link)update
inDao
to detect and delete relational objects that are no longer associated with the object (link, link, link)