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

Improve state restoration performance #4531

Merged
merged 8 commits into from May 26, 2023
Merged

Improve state restoration performance #4531

merged 8 commits into from May 26, 2023

Conversation

tonisevener
Copy link
Collaborator

@tonisevener tonisevener commented May 23, 2023

Phabricator:
https://phabricator.wikimedia.org/T337073

Notes

This PR simplifies state restoration to only the user's last read article, to reduce the chance of prolonged state restoration times upon launch. It also fixes a couple of bugs that originally caused a situation where the user was stuck in a Reading List Detail modal state upon restoration. Test steps for each commit are below.

6485b92 - This fixed a bug where there was a missing close button upon state restoration to a modal Reading List Detail screen. This area of code isn't actually hit anymore due to later commits in this PR, but I decided to fix it anyway in case we bring full view controller hierarchy restoration back in the future. You must git checkout this SHA if you want to test it. Test steps for this are:

  1. Go to an article, tap saved button in bottom toolbar
  2. In the toast, tap to save to a reading list
  3. In the next toast, tap to view reading list
  4. On reading list detail modal screen, background the app, then terminate. Re-launch the app. Confirm Close button shows when the Reading List Detail modal is restored. It does not show in main.

92c22db and 0b9740a - This prevents pushing on an article from a Reading List Detail modal. Instead it dismisses the modal upon cell tap, then pushes on the article onto the stack below. Test steps are:

  1. Go to an article, tap saved button in bottom toolbar
  2. In the toast, tap to save to a reading list
  3. In the next toast, tap to view reading list
  4. On reading list detail modal screen, tap an article. Confirm modal dismisses and article is pushed onto navigation stack beneath.
  5. Regression: Go to Saved tab > Reading Lists > Reading lists detail. Tap an article, confirm article is pushed on as before.
  6. Regression: Go to Saved tab > All articles. Tap an article, confirm article is pushed on as before.

b4c0bcf - This is the bigger change with simplifying state restoration. I kept the way we persist navigation state as-is, but now upon state restoration, this only seeks out the top-most article, and pushes that onto the root navigation stack.

  1. Create a simple rabbit hole from tapping on the Explore feed featured article card. Then background and terminate via the app switcher. Relaunch the app, confirm your last article is restored. Confirm tapping "Back" takes you back to the home screen (i.e. no other parts of the stack are restored).
  2. Create a rabbit hole in a modal from tapping on the Explore feed > Top read card > All top read articles. Background and terminate via the app switcher. Relaunch the app, confirm your last article is restored. Confirm tapping "Back" takes you back to the home screen.
  3. Create another rabbit hole from app Settings > Your talk page. If possible, try to reach an article from this flow. Terminate the app and confirm only the article restores like the previous test steps.
  4. Create a navigation stack where there is no article view. Confirm it launches on the home screen.

Marking as Draft while we confirm this direction with product / design.

@tonisevener tonisevener requested a review from staykids May 23, 2023 15:59
@tonisevener tonisevener marked this pull request as draft May 23, 2023 15:59
@tonisevener tonisevener marked this pull request as ready for review May 24, 2023 19:05
@tonisevener tonisevener changed the title [Hold] Improve state restoration performance Improve state restoration performance May 24, 2023
@@ -21,6 +21,78 @@ final class NavigationStateController: NSObject {
private typealias Presentation = ViewController.Presentation
private typealias Info = ViewController.Info

/// Finds the topmost article from persisted NavigationState and pushes it onto navigationController
@objc func restoreLastArticle(for navigationController: UINavigationController, in moc: NSManagedObjectContext, with theme: Theme, completion: @escaping () -> Void) {
guard let tabBarController = navigationController.viewControllers.first as? UITabBarController else {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this warning can be alleviated with:

guard navigationController.viewControllers.first is UITabBarController else { ...

(Also very cool to see the Xcode Cloud warnings propagating up to the code review layer here in GitHub!)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

‼️ That is very cool! This is fixed.

return childArticleViewController ?? articleViewController
}

/// Attempts to restore user's entire heirarchy, included presented modal navigation stacks. Currently not in use in preference of restoreLastArticle to improve loading times.
Copy link
Contributor

Choose a reason for hiding this comment

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

@tonisevener Super minor: typos heirarchy → hierarchy, included → including.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah sorry about that, this is fixed (also in other places I found).

Copy link
Contributor

@staykids staykids left a comment

Choose a reason for hiding this comment

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

Awesome - working as expected for me so far. Hoping it makes an impact for our users!

@staykids staykids merged commit e929595 into main May 26, 2023
2 checks passed
@staykids staykids deleted the T337073 branch May 26, 2023 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants