Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Retrieve sphere ID from UserDefaults and run recovery check earlier #909

Merged
merged 3 commits into from
Sep 28, 2023

Conversation

gordonbrander
Copy link
Collaborator

Previously, we were reading the known sphere identity from the SQLite database. This is suboptimal for a couple reasons:

  • The database is an index, not a source of truth, and can be thrown away and re-built at any time.
  • The source of truth for the known sphere identity is AppDefaults.standard.sphereIdentity (UserDefaults)
    • We store the identity here upon sphere creation
    • UserDefaults persist for the life of the app container
  • Relying on the database meant we had to wait until database migration was complete before checking for recovery state.

This PR makes the following changes:

  • Read known sphere identity from AppDefaults.standard.sphereIdentity
  • Run recovery check as early as possible (.start)

Additionally, I added some logs to NoosphereService to make it clearer when we experience a cache miss due to failure to construct sphere.

We should have been running recovery check against the sphere identity
stored in UserDefaults. This is available immediately, so we should just
go ahead and start recovery check at .start.
@gordonbrander
Copy link
Collaborator Author

Playtested recovery on simulator successfully.

Steps:

  • Create sphere with app client at Noosphere v0.14.x
  • Redeem invite code
  • Make some notes
  • Sync
  • Update to this branch, with client at Noosphere v0.15.0
  • Recover

Comment on lines +2456 to +2461
// Get any existing sphere identity stored in UserDefaults
// If none, it's the first run, nothing to recover
guard let userDefaultsIdentity = AppDefaults.standard.sphereIdentity?
.toDid() else {
return AppAction.presentRecoveryMode(false)
}
Copy link
Collaborator

@bfollington bfollington Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check the persisted DID first, if there isn't one we should skip recovery mode.

Tested on Simulator.

@bfollington bfollington merged commit 83184f8 into main Sep 28, 2023
@bfollington bfollington deleted the 2023-09-28-run-recovery-check-earlier branch September 28, 2023 21:53
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
Status: 🌱 Done
Development

Successfully merging this pull request may close these issues.

2 participants