plone / Products.CMFPlone

The core of the Plone content management system
https://plone.org
GNU General Public License v2.0
250 stars 188 forks source link

Image data isn't cleared on database after deleting an image from an object's field #3720

Open margaridasp opened 1 year ago

margaridasp commented 1 year ago

Image data isn't cleared on database after deleting an image from an object's field

What I did:

This was done on Plone 5.2.10 and RelStorage 3.5.0 with PostgreSQL 14.6

What I expect to happen:

I expected the blob_chunk table to be empty after deleting the image associated with the object and packing the database.

What actually happened:

After deleting the image and packing the database, 2 rows are left on the blob_chunk db table. I believe it has to do with the image scales, because if I open a debug console and delete the AnnotationStorage for the object, through the code below and then pack the database, then the rows in the blob_chunk table of the db do disappear.

from plone import api
from plone.scale.storage import AnnotationStorage
import transaction
portal = api.portal.get()
obj = portal['example']
AnnotationStorage(obj).clear()
transaction.commit()
davisagli commented 1 year ago

@margaridasp Did you delete the entire content item, or just clear the current image from the image field?

margaridasp commented 1 year ago

@margaridasp Did you delete the entire content item, or just clear the current image from the image field?

@davisagli sorry for the confusion! I just cleared the image from the image field on the object!

davisagli commented 12 months ago

I think this is behaving as designed. Old image scales are kept for 24 hours so that if there are still references to them from a cached page, they can still be served. After 24 hours they should be cleaned up via this code: https://github.com/plone/plone.scale/blob/master/plone/scale/storage.py#L329

Of course this is a complicated area and it's possible that something is still not working correctly, but that's why I'm not surprised that the scales are still there.