Asynchronous Blog Loading Plan
The current BlogService refreshes all posts at startup using @PostConstruct. This blocks the application until XWiki calls complete. We want to make the initial refresh non‑blocking.
Option 1 – Initial load in parallel
- Replace the
@PostConstructannotation onrefreshPosts. - Create an
@EventListener(ApplicationReadyEvent.class)method that runsrefreshPosts()in a new thread. Example:@EventListener(ApplicationReadyEvent.class) public void loadPostsAsync() { CompletableFuture.runAsync(this::refreshPosts); } - Keep the existing
@Scheduledannotation for periodic updates. - Update health checks to handle the case where posts are still loading (empty list is acceptable at startup).
Option 2 – Load on demand
- Remove startup refresh entirely.
- When a controller calls
getPosts()orgetPostsByUrl(), check if the internal lists are empty andloadingisfalse. - If so, trigger
refreshPosts()asynchronously in a background thread while returning an empty result to the caller. - Optionally expose an administrative endpoint to force a refresh.
Both approaches avoid blocking application startup and allow blog content to become available once loaded.