Repository navigation
fix(sync): auto-regenerate thumbnail sizes left stale after an image edit - #1314
Open
gabrielcld2 wants to merge 2 commits into
Open
gabrielcld2 wants to merge 2 commits into
gabrielcld2 wants to merge 2 commits into
Conversation
…edit Editing an image via the WP image editor can rename the main file without regenerating its registered thumbnail sizes, leaving `sizes` metadata pointing at filenames that no longer exist. This causes Delivery::find_attachment_size_urls() to run an uncached wp_postmeta lookup on every render of that attachment, since nothing resolves the stale URLs. Adds a `sizes` sync type (mirroring the existing `edit` type) that detects this drift on render via the existing realtime sync pipeline and regenerates the attachment metadata, self-healing both new edits and already-drifted attachments without any new cron job or bulk scan.
wp_get_attachment_metadata()'s PHPDoc already types 'sizes' as array, making the is_array() check dead code; empty() already covers the missing-key and empty-array cases.
gabrielcld2
marked this pull request as ready for review
October 12, 2026 12:38
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The issue
Editing an image via the WordPress image editor (crop/scale) can rename the main attached file (adding an
-e{timestamp}suffix) without regenerating its registered thumbnailsizes.The
sizesmetadata is left pointing at the pre-edit filenames, which no longer exist on disk and have no matching entry inwp_cloudinary_relationships.Every render of that attachment then falls through to
Delivery::find_attachment_size_urls(), which runs an uncachedwp_postmetaquery trying (and failing) to resolve the stale URL.On high-traffic pages (e.g. a site icon used on every page) this becomes a query on every single request.
The fix
This adds a new
sizessync type, modeled directly on the existingeditsync type:Media::has_outdated_sizes()(php/class-media.php) detects when thesizesmetadata's filenames no longer match the current attached file's basename.Upload_Sync::regenerate_sizes()(php/sync/class-upload-sync.php) callswp_generate_attachment_metadata()to rebuild the sizes, then persists the new signature viaset_signature_item()so it doesn't re-run on every subsequent render.Because this rides the existing realtime sync pipeline, it self-heals both future edits and attachments that are already drifted today.
i.e. no new cron job, scheduled scan, or admin action required. No code changes needed outside these three files.
Limitations
QA notes
Requires an attachment already synced to Cloudinary (shows a Cloudinary status / has a Public ID in the Media Library) — this is what lets the drift-detection logic run on render.
Manual steps:
-e{timestamp}) but, ondevelop, leaves the registered thumbnail sizes pointing at the old filename.Outdated sizes: YES - bug present.develop: stillYES - bug present— never fixes itself.no - in sync, and the sizes list shows the new, edited filenames.Script (
qa-check-sizes.php) — read-only, auto-detects the most recently edited image attachment, no ID needed: