refactor(mobile): full-sync ratings on startup, SSE only for updates - #46
Merged
Conversation
Mobile was refetching /api/ratings?bbox=… on every onCameraIdle (every pan/zoom). Swap for a single full-sync fetch over a fixed Berlin bbox at attach + auth-change, and rely on the existing SSE channel for updates. Panning no longer hits the network. - New `kBerlinSyncBbox` covers Berlin + ~5km padding; reused for startup sync and every SSE invalidate refetch. - Deleted rating_fetch_policy (viewport expansion, safe-inner dedup, min-zoom gate) — all dead with camera-idle gone. - RatingOverlayController now exposes RatingOverlayState with a liveSyncDegraded flag that flips true when SSE is off (client flag or server 404). Map screen shows a one-shot SnackBar so users know their paintings only sync on app start until they relaunch. - RatingEventsClient gains an onServerDisabled callback so the 404 latch propagates to the UI without polling.
…a8a405 # Conflicts: # mobile/lib/screens/map_screen.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Mobile was refetching
/api/ratings?bbox=…on everyonCameraIdle— every pan and zoom hit the network. Swap to:kBerlinSyncBbox, ~5km padding around the Berlin ring).invalidateonly. Every invalidate refetches the same full bbox.If SSE is unavailable (client kill-switch off or server 404s
/api/ratings/events), the overlay goes stale until next app start. A one-shotSnackBartells the user.Backend unchanged — same
/api/ratings?bbox=…endpoint.Changes
mobile/lib/config/berlin_bounds.dart— new;Bboxtype +kBerlinSyncBboxconstant.mobile/lib/providers/rating_overlay_provider.dart— gutted.Notifier<RatingOverlayState>with aliveSyncDegradedflag. Camera probe /onCameraIdle/_lastFetched/ fetch-policy all gone.mobile/lib/services/rating_events_client.dart— newonServerDisabledcallback fires once when 404 latches, so the controller can surface the degraded state.mobile/lib/screens/map_screen.dart— removed theonCameraIdlecall into the rating overlay; added aref.listenthat shows aSnackBarwhenliveSyncDegradedflips true.mobile/lib/services/rating_fetch_policy.dart+ its test (viewport expansion, safe-inner dedup, min-zoom gate — all dead with camera-idle gone).rating_overlay_controller_test.dartaround the new sync model.Known follow-up
SSE reliability issue ("doesn't work" on device) is not addressed here — tracked as a separate task. This PR only changes when/how syncs are triggered.
Test plan
just test-mobile— 113 passed, analyzer clean.just preview(worktree) +just dev-ios-sim, signed-in:GET /api/ratings?bbox=12.9,52.25,13.9,52.75./api/ratingsrequests.invalidate→ one refetch, overlay updates without user pan.BEEBEEBIKE_RATINGS_SSE_ENABLED=false, restart backend + app → one startup fetch, SSE 404s, toast appears once, no further fetches.--dart-define=BEEBEEBIKE_RATINGS_SSE_ENABLED=false→ startup fetch, no SSE attempt, toast on first map load.