You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add `reset_stale_fetching_states_internal` to `WpApiCache` that resets
`FetchingFirstPage` and `FetchingNextPage` states to `Idle` after migrations.
This prevents perpetual loading indicators when the app is killed during a
fetch operation. The reset runs in `perform_migrations()` because `WpApiCache`
is typically created once at app startup, unlike `MetadataService` which is
instantiated per-service.
Changes:
- Add `reset_stale_fetching_states_internal()` with comprehensive docs
- Call from `perform_migrations()` after migrations complete
- Add session handover document for MetadataService implementation
-`wp_mobile_cache`: 112 tests (31 new for list_metadata)
44
+
-`wp_mobile`: 60 tests (15 new for MetadataService)
45
+
46
+
---
47
+
48
+
## Stale State on App Launch ✅ RESOLVED
49
+
50
+
### Problem
51
+
52
+
The `ListState` enum includes transient states (`FetchingFirstPage`, `FetchingNextPage`) that should not persist across app launches. If the app crashes during a fetch, these states remain in the database, causing perpetual loading indicators or blocked fetches on next launch.
53
+
54
+
### Solution Implemented
55
+
56
+
**Option B: Reset on `WpApiCache` initialization** was chosen.
57
+
58
+
After `perform_migrations()` completes, we reset all fetching states to `Idle`:
Option A (reset in `MetadataService::new()`) was rejected because `MetadataService` is not a singleton. Multiple services (PostService, CommentService, etc.) each create their own `MetadataService` instance. Resetting on each instantiation would incorrectly reset states when a new service is created mid-session.
68
+
69
+
`WpApiCache` is typically created once at app startup, making it the right timing for session-boundary cleanup.
70
+
71
+
### Design Decisions
72
+
73
+
-**`Error` state is NOT reset**: It represents a completed (failed) operation, not an in-progress one. Preserving it allows UI to show "last sync failed" and aids debugging.
74
+
-**Logs when states are reset**: Helps debugging by printing count of reset states.
75
+
76
+
### Theoretical Issues (Documented in Code)
77
+
78
+
If an app architecture creates multiple `WpApiCache` instances during a session (e.g., recreating after user logout/login), this would reset in-progress fetches. In practice this is rare, but the documentation in `WpApiCache::reset_stale_fetching_states_internal` explains alternatives if needed.
79
+
80
+
See full documentation in `wp_mobile_cache/src/lib.rs`.
81
+
82
+
---
83
+
84
+
## Remaining Work
85
+
86
+
See `metadata_service_implementation_plan.md` for full details:
87
+
88
+
-**Phase 3.3**: Update collection creation to use sync callback
89
+
-**Phase 3.4**: Remove deprecated in-memory store (after migration)
90
+
-**Phase 4**: Observer split (data vs state observers)
0 commit comments