-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prune Image Cropper and Media Picker (v3) values #11805
Prune Image Cropper and Media Picker (v3) values #11805
Conversation
Besides storing less data in the Because media doesn't have versions, just re-saving them from the back-office will prune the existing values. For content, re-saving would result in a new version with the now pruned values (which would actually increase the database size slightly). Data reduction will only happen after publishing the content, as that will update NuCache (although previewing should already update the draft version in the cache). You can use the Content Version Policy (introduced in PR #11495) to remove old versions, so you only store the latest, pruned values... To see how much data can be saved, I've written scripts that prunes existing data: https://gist.github.com/ronaldbarendse/cda65cb041c149e943d4be67ed091da0. I've taken a medium-sized production database that contained 1109 rows of ImageCropper property data (only on media). The values of all rows combined contained 963.852 characters, the After running the prune script, the total characters went down from 963.852 to 72.505 characters, that's only 7,5% of the original size! 🤯 After rebuilding the tables and shrinking the database, the All in all, this can quickly add up, especially when a site has a lot of media items and/or configured crops. |
The Examine indexes will also benefit from this, as both the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@elit0451 I can't replicate the issue with the coordinates having |
Hi again, |
…agecropper-mediapicker3-values
Update ❗ After clearing the cache, the issue didn't persist, so I am happy to merge 😊 |
Prerequisites
Description
By default, Umbraco stores indented JSON values with redundant crop/default focal point values to the database for all Image Cropper and Media Picker (v3, with local crops) property data. You can view the existing data for both editors by doing the following database queries:
On a clean Umbraco 8 install (
v8/dev
) with The Starter Kit, the image crop data on media is stored without indenting, but still contains an empty crops value (this is probably directly populated by the package install):After saving this media item in the back-office, it now contains indentation and also the default focal point, which both bloats this value from 67 characters to 138 (more than double):
This gets even worse when you start configuring crops, as the crops are also stored in the property data, even when you've not changed the crop coordinates. After adding 2 crops to the Image Cropper data type (Avatar 100x100 and Hero 1920x200) and saving the media item again, the value is now 360 characters:
There's already code available to apply any missing configured crops to this value (added in #6950), so we don't have to store the crops when it doesn't have coordinates (the width/height is always redundant). The focal point is also optional and the code already deals with a missing value, so there's no need to store the default centered (0.5,0.5) value.
The same happens for the Media Picker (v3), because that also stores redundant values for the local crops and focal point. This PR updates both editors to prune the values in
IDataValueEditor.FromEditor()
and re-add the configured crops in theIDataValueEditor.ToEditor()
method.Make sure you've observed the above cases and then apply this PR. After saving the media item, the following data should be stored in the database:
If you change the focal point and save, this should be the only thing that's added:
After resetting the focal point (which is added in PR #10923) and changing one of the crops, only the crop alias and coordinates are now stored on save:
The same can be tested for the Media Picker by enabling the local focal point and adding custom crops to the picker. Also make sure the pruned data is added back when rendering the value on the front-end, e.g. by including the following in the
Home.cshtml
view:This returns a serialized version of the
ImageCropperValue
that's used in theGetCropUrl()
method and should include all crops with their dimensions, e.g.: