Do not delete thumbnail queue when replacing an asset

Thumbnails are normally created on demand, e.g. when processing the format codes in a post's body text.
Normally, the temporary URL is only used once to generate thumbnails ad-hoc. However, when cache is
enabled, a reference to the asset may be used in a cached version of a formatted body text, skipping
the normal thumbnail generation routine.

When an asset is replaced, currently, all thumbnails are removed and references to them are removed
from the database. In case the asset is still referenced in a cached formatted body text, this could lead
to an error when requesting the thumbnail, as the thumbnail request is no longer present in the system.

As we do not know what posts use particular assets at this point in the code, it is best to work around this
issue by unsetting the thumbnail filenames rather than deleting the entries outright. This effectively
generates them again on the next request.

In the future, we should aim to keep track of what posts make use of assets, so cache may be invalidated
in a more targeted way.
This commit is contained in:
Aaron van Geffen 2022-07-07 14:22:22 +02:00
parent 36a2779381
commit 58b7204fbf

View File

@ -158,7 +158,8 @@ class Image extends Asset
} }
return Registry::get('db')->query(' return Registry::get('db')->query('
DELETE FROM assets_thumbs UPDATE assets_thumbs
SET filename = NULL
WHERE id_asset = {int:id_asset}', WHERE id_asset = {int:id_asset}',
['id_asset' => $this->id_asset]); ['id_asset' => $this->id_asset]);
} }