wordpress-mobile / wordpress-mobile/WordPress-Android

Duplicate fetchEditorCapabilitiesForSite call between GutenbergEditorPreloader and SiteConnectivityBannerViewModelSlice

Open
#22,880 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

[Type] Tech Debt
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 (shouldPreload state map in the preloader; fetchedCapabilitiesForSite set 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

  1. In-flight dedup at the EditorSettingsRepository layer (e.g. a per-site Deferred cache that the second caller awaits).
  2. 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).
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.