Repository navigation
[6.x] Batch asset reference updates when moving or deleting many assets - #15866
Open
ryanmitchell wants to merge 1 commit into
Open
ryanmitchell wants to merge 1 commit into
ryanmitchell wants to merge 1 commit into
Conversation
Moving or deleting an asset folder moved or deleted each asset in it, and every asset queued its own UpdateAssetReferences job. Each job scans all the content on the site, so a folder of N assets meant N full scans, which times out on content-heavy sites. UpdateAssetReferences::batch() collects the asset moves and deletions made inside a callback (via the listener's shouldQueue hook) and updates their references in a single pass, queued as one chained job per 500 moves. Asset folder moves and deletes, and the bulk move, move folder, rename folder and delete actions, now run inside a batch. Moves are applied to each item in the order they happened, and each item's data is encoded once per pass rather than once per move. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Fixes #13813.
Moving, renaming or deleting an asset folder moves or deletes each asset in it, and every asset queued its own
UpdateAssetReferencesjob. Each of those jobs scans all the content on the site (entries, terms, globals, users), so a folder of N assets meant N full scans. On content-heavy sites the jobs time out and the references are never updated. Selecting many assets in the CP and moving or deleting them had the same problem.This PR adds
UpdateAssetReferences::batch():shouldQueue()(which Laravel calls when the event is dispatched) records each saved or deleted asset's original and new paths instead of queueing a job.UpdateBatchedAssetReferencesjob. Large batches are split into chunks of 500 moves, chained so they run in order. The jobs only carry paths, so the payload stays small.AssetFolder::move()andAssetFolder::delete()run inside a batch, as do theMoveAsset,MoveAssetFolder,RenameAssetFolderandDeleteactions.Each item's data is also JSON-encoded once per pass rather than once per move, by reusing the pre-filter from #15089 through two new static helpers on
DataReferenceUpdater.Benchmarks
Stache, 10,000 entries, renaming a folder with 20 assets:
Renaming a folder with 500 assets across 5,000 entries now takes 4.1s, of which 1.6s is moving the files themselves. Before, it would take 500 full scans.
Notes
AssetReferencesUpdatedis still dispatched once per asset whose references were updated. For a deleted asset, the event gets an asset made with the container and the original path.🤖 Generated with Claude Code