Move database cache rebuild to a background task with polling #18496
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.
Prerequisites
This was raised as an issue in Umbraco Cloud for large sites where the time to rebuild the database cache is quite long. It may go over the hard limit imposed by Cloudflare and although the work continues, the user has no indication that it's completed.
Description
This PR updates the database cache rebuild operation to move it from a single request/response to a pattern where we submit the task, run in in the background and poll for completion.
It is based on what we are already doing for Examine index rebuilds, so it's a pattern and technique already in use in the CMS that I've just applied to this operation.
I've had a think and some discussion about the question of could we use SignalR? Answer is yes, probably, and likely would be a more elegant solution - but my first finding on looking into this was that we already had a "submit and poll" solution in place for the Examine re-indexing. So given we had that pattern already, the quickest solution was just to replicate that for the other long-running operations (database cache rebuild and publish with descendants). Would be a bigger effort to rework, particularly if we were to support reporting progress rather than just "done".
So I'm considering maybe it's better to keep and extend the polling solution to resolve the problem for Cloud, and if we improve it later, then of course that's great.
Testing
To test you can use the UI under Settings > Published Status and click the Rebuild Database Cache button. If you delete all records from
cmsContentNu
first you can see that they are recreated when the operation is completed.