wordpress-mobile / wordpress-mobile/WordPress-Android
Duplicate fetchEditorCapabilitiesForSite call between GutenbergEditorPreloader and SiteConnectivityBannerViewModelSlice
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 3.2k
- Forks
- 1.4k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 69
Description
Background
Two callers independently invoke EditorSettingsRepository.fetchEditorCapabilitiesForSite(site) during MySiteViewModel.refresh() and onResume():
GutenbergEditorPreloader.preloadIfNeeded/refreshPreloading— added in #22579.SiteConnectivityBannerViewModelSlice.fetchCapabilities— added in #22834.
Both fire on every refresh and resume, so on a cold launch both callers race the same fetch.
EditorSettingsRepository.fetchEditorCapabilitiesForSite has no in-flight deduplication — each call fans out two async requests (fetchRouteSupport, fetchThemeBlockStyleSupport) and they all write back to the same appPrefsWrapper keys. So a first-launch refresh issues 4 parallel HTTP requests when one would do, with last-write-wins races on shared prefs.
Mitigating factors
- Both callers have per-session dedup after a successful fetch (
shouldPreloadstate map in the preloader;fetchedCapabilitiesForSiteset in the slice), so the duplicate only happens on the first call per site per session. - The shared-prefs race is usually benign — both writers write the same value — but it's wasted bandwidth and a small thundering-herd on the WP API for the apiRoot fetch.
Possible fixes
- In-flight dedup at the
EditorSettingsRepositorylayer (e.g. a per-siteDeferredcache that the second caller awaits). - Have the connectivity slice observe the preloader's result (the preloader is the de-facto driver of editor capabilities; the slice's banner is downstream of whether that fetch succeeded).
- Inverse: have the preloader observe the slice (less natural — the slice exists to react to the fetch, not own it).
Option 2 is the cleanest if the preloader's fetch path can expose a success/failure signal the slice can subscribe to.
Related
- #22579 (introduced
GutenbergEditorPreloader) - #22834 (introduced the connectivity-banner slice)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading EditorSettingsRepository.fetchEditorCapabilitiesForSite and the callers GutenbergEditorPreloader.preloadIfNeeded/refreshPreloading and SiteConnectivityBannerViewModelSlice.fetchCapabilities. Compare their per-session state and determine whether repository-level in-flight deduplication or sharing the preloader result best fits the existing flow. Done means a cold-launch refresh performs one capabilities fetch, with the connectivity banner still receiving the fetch's success or failure.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, kotlin
- Domain
- mobile
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100