Skip to content

Rate-limit remote feature-flag and remote-config fetches - #26189

Open
feather2222 wants to merge 1 commit into
wordpress-mobile:trunkfrom
feather2222:issue/25665-remote-store-rate-limit
Open

feather2222 wants to merge 1 commit into
wordpress-mobile:trunkfrom
feather2222:issue/25665-remote-store-rate-limit

Conversation

@feather2222

Copy link
Copy Markdown
Contributor

Problem

Follow-up to #25643: after the UIScene adoption, WordPressAppDelegate refreshes the remote stores in both willFinishLaunching and the foreground transition that fires right after the first scene connect, so updateFeatureFlags() / updateRemoteConfig() run twice on every cold launch.

The deeper gap (per the issue): the stores have no client-side fetch throttle, so any caller asking twice in quick succession hits the network twice. RemoteFeatureFlagStore even cancels the in-flight request and refetches; RemoteConfigStore just fires again.

Fix

Give each store a persisted last-fetched date and a 5-minute minimum refresh interval, shaped after the existing AppUpdateCoordinator.shouldFetchAppStoreInfo prior art:

  • update() within the interval serves the cache and still invokes its callback (callers' UI continuation behavior unchanged).
  • force: true bypasses the limit — used by AccountHelper on logout and by updateFeatureFlags(authToken:) when an explicit token is passed, since flags are customized per-user server-side (the caveat called out in the issue).
  • Failed fetches don't stamp the last-fetched date, so retries aren't suppressed.
  • The interval is injectable (minimumRefreshInterval) for testing.

This subsumes the #25643 cold-launch double-fetch, so no one-off debounce in the AppDelegate is needed.

Tests

Added unit tests for both stores: skip-within-interval, forced refresh bypass, recent-fetch skip, fetch-after-interval, and retry-not-suppressed-after-failure. The existing double-fetch test in RemoteFeatureFlagTests now passes minimumRefreshInterval: 0 to preserve its original semantics.

To test

  1. Cold-launch the app: feature flags / remote config fetch once; the second update() from the foreground transition logs "Skipping … fetched recently" instead of hitting the network.
  2. Log out: flags refetch immediately (forced).
  3. Unit tests: RemoteFeatureFlagTests, RemoteConfigStoreRateLimitTests.

Fixes #25665

After the UIScene adoption (wordpress-mobile#25643), WordPressAppDelegate refreshes
both stores on cold launch twice (willFinishLaunch + the foreground
transition), and the stores themselves have no client-side throttle,
so any caller asking twice in quick succession hits the network twice.

Give each store a persisted last-fetched date and a 5-minute minimum
refresh interval, shaped after AppUpdateCoordinator.shouldFetchAppStoreInfo:
update() serves the cache (still invoking its callback) within the
interval. A force: bypass keeps per-user flag refreshes working on
account change/logout, and failed fetches don't stamp the date so
retries aren't suppressed.

Fixes wordpress-mobile#25665
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a client-side rate limit for remote feature-flag / remote-config fetches

1 participant