Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage Migration: Sync before starting storage migration #13356

Merged
merged 7 commits into from
Mar 24, 2023

Conversation

david-allison
Copy link
Member

@david-allison david-allison commented Feb 28, 2023

Purpose / Description

If a user is going to perform a migration, they should be fully synced to ensure no data loss. We can't easily know if they're fully synced on the media side of things, so perform a sync and see.

When the user has performed a media sync, migrate.

The sync may complete while the user has the app closed.

In this case, withProgress may not execute (no window), so we conservatively pause the start of the migration until the AnkiDroid window has called onResume.

Also handle the case where the media sync cannot occur (via AlertDialog + migrate anyway).

Fixes

Approach

Define an AsyncOperation: similar to an AsyncDialogFragment, but not necessarily with a dialog

Define a MigrateStorageAfterSync
It passes this into sync, which calls it at the end of the operation

Define a onSyncCompleted() listener, as an interface so the sync functionality can be decoupled from DeckPicker in future.

Handle the activity lifecycle changes in DeckPicker, which required a minor rework of DialogHandler + AnkiActivity

How Has This Been Tested?

Screenshot 2023-03-07 at 00 11 31
Screenshot 2023-03-06 at 23 32 41
Screenshot 2023-03-06 at 23 29 11

Learning

renderPage() needs a lot of work for the new Backend

Checklist

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@david-allison david-allison marked this pull request as draft February 28, 2023 01:29
@github-actions
Copy link
Contributor

Message to maintainers, this PR contains strings changes.

  1. Before merging this PR, it is best to run the "Sync Translations" GitHub action, then make and merge a PR from the i18n_sync branch to get translations cleaned out.
  2. Then merge this PR, and immediately do another translation PR so the huge change made by this PR's key changes are all by themselves.

Read more about updating strings on the wiki,

@david-allison david-allison force-pushed the storage-migration-sync branch 3 times, most recently from a86f5cd to ab47dc5 Compare February 28, 2023 01:37
@david-allison david-allison mentioned this pull request Feb 28, 2023
5 tasks
@david-allison david-allison added Review High Priority Request for high priority review Scoped storage labels Feb 28, 2023
@david-allison david-allison added the Needs Author Reply Waiting for a reply from the original author label Mar 6, 2023
@david-allison david-allison force-pushed the storage-migration-sync branch 2 times, most recently from 70ee216 to c68a48f Compare March 7, 2023 00:06
@david-allison david-allison added Needs Author Reply Waiting for a reply from the original author and removed Needs Author Reply Waiting for a reply from the original author labels Mar 7, 2023
@david-allison david-allison changed the title [Pre-Review] Storage Migration: Refactor & Sync before starting storage migration Storage Migration: Refactor & Sync before starting storage migration Mar 7, 2023
@david-allison david-allison removed the Needs Author Reply Waiting for a reply from the original author label Mar 7, 2023
@david-allison david-allison marked this pull request as ready for review March 7, 2023 02:17
@david-allison david-allison changed the title Storage Migration: Refactor & Sync before starting storage migration Storage Migration: Sync before starting storage migration Mar 7, 2023
val message = """${getString(R.string.migration_update_request)}
<br>
<br>${getString(ifYouUninstallMessageId)}"""
val message = getString(R.string.migration_update_request_requires_media_sync)
Copy link
Member Author

Choose a reason for hiding this comment

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

A user will now always be logged in

Displays a notification if the app is paused
otherwise performs the operation

Similar to 'DialogHandler', but doesn't require a dialog
We need to move the user's data to /Android/ to handle scoped storage
changes. Before we perform this migration, we should ensure that users
data is safe. To do this, we enforce a sync.

A user should have completed a full media sync before the migration
occurs.

This ensures that their data is up to date and can be restored if
anything goes awry with the migration

Dialog wording as discussed on the Figma, with the exception of
changing 'sync' to 'media sync'

Issue 5304
We need a media sync before a storage migration.

If this has been disabled, it is the user's responsibility
to perform a sync before this migration occurs

There are currently two reasons:

Fetch media on Sync is set to:
* 'Only if unmetered' & connection is metered
* Never

Issue 5304
Caused bugs when performing a storage migration after syncing
If a migration requires a sync, and a sync completes when the app is
 paused, a notification occurs prompting the user to migrate.

This is handled by `DialogHandler`, which runs in AnkiActivity.onResume
BEFORE `loadDeckCounts`.

This races with closing the collection for a storage migration.

Instead, start the task and allow it to be stopped.

Issue 5304
Copy link
Member

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

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

Seems fine - strings are relatively clear (that is: merge-able / cleared out from real translation changes), needs a good second look but is de-conflicted and seems ready to go

@mikehardy mikehardy added Needs Second Approval Has one approval, one more approval to merge and removed Review High Priority Request for high priority review labels Mar 24, 2023
Copy link
Member

@lukstbit lukstbit left a comment

Choose a reason for hiding this comment

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

Reviewed the changes and it seems fine to me, so LGTM
I'm going to wait until tomorrow, if Brayan wants to take a look otherwise I'm going to merge it myself.

@lukstbit lukstbit added Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Second Approval Has one approval, one more approval to merge labels Mar 24, 2023
@mikehardy
Copy link
Member

Given two sets of eyes and the ability to do follow-ons plus the current strings situation (clear: ready to merge) I'm going to go ahead and merge this one and keep the scoped storage train moving down the tracks. Thank you @lukstbit !

@mikehardy mikehardy merged commit be62538 into ankidroid:main Mar 24, 2023
@github-actions github-actions bot added this to the 2.16 release milestone Mar 24, 2023
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Mar 24, 2023
@david-allison david-allison deleted the storage-migration-sync branch April 27, 2023 13:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Scoped storage - sync before migration
3 participants