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

Feature/placed pages pagination #10264

Merged
merged 7 commits into from Oct 19, 2018
Merged

Conversation

danielebogo
Copy link
Contributor

@danielebogo danielebogo commented Oct 16, 2018

This PR allows the pages list to load all the pages till the end, without using the infinite scroll feature as before.

Page List has a new WPContentSyncHelper called PageContentSyncHelper in charge to recursively call syncMoreContent till it has no more content.

To test:

  • Open a blog and check if all the pages are loaded

@aerych do you mind to have a look since we already spoke about this?

Copy link
Member

@aerych aerych left a comment

Choose a reason for hiding this comment

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

Heya @danielebogo
Thanks for tackling this. I noticed a few things in the review and testing that I think we should consider.

Apart from the comments in the code, when I started testing in the simulator I noticed the page list will stutter or momentarily freeze when a batch of pages are saved and the list is updated. This doesn't seem like a great experience for the user. I think the experience would be better to sync everything before refreshing the list.

In this patch the ViewController syncs in batches. This made sense when we had the Load More functionality but since we want to load all pages it would be better for the service to do this job. I'd consider updating the service so it would fetch all pages and when everything was synced then execute its success block. This would probably need to be a new method to handle the logic so it doesn't conflict with the way the post list syncs. This would let the list refresh once and keep the user experience a bit nicer. The first sync might end up showing the Loading message for a while but that should only happen once.

Thoughts?



class PageContentSyncHelper: WPContentSyncHelper {
override func syncContentEnded(error: Bool) {
Copy link
Member

Choose a reason for hiding this comment

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

Here we're subclassing in order to override one method where the method body is largely duplicated.

For a lighter touch, and to avoid duplication, it might make sense to instead override syncContentEnded in PageListViewController like so:

override func syncContentEnded(_ syncHelper: WPContentSyncHelper) {
        if syncHelper.hasMoreContent {
            syncHelper.syncMoreContent()
        } else {
            super.syncContentEnded(syncHelper)
        }
    }

What do you think?

@@ -45,6 +45,20 @@ class PageListViewController: AbstractPostListViewController, UIViewControllerRe
}
}

@objc private lazy var _syncHelper: PageContentSyncHelper = {
let syncHelper = PageContentSyncHelper()
Copy link
Member

Choose a reason for hiding this comment

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

I think the change I suggested above would avoid the need for this or for customizing the getter/setter below.

@danielebogo
Copy link
Contributor Author

Thanks @aerych for the hint. Yes you are right, the freeze happened because of the purgeLocalSync that was applied for every batch.
So the fix now affect only the PostService. The syncPost method use a recursion to load and sync/save the remote posts at the end. In this way the sync delegate use one function only and doesn't call the load more anymore (that actually is a duplication too).
Let me know what you think 😉!

Copy link
Member

@aerych aerych left a comment

Choose a reason for hiding this comment

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

Heya @danielebogo! Loving this change. I took it for a spin with a few different blogs. Blogs with a few dozen pages are super fast. I stress tested with a blog that had ~2500 pages and while it took ages to load it worked as expected.

Just wanting to note on the blog with 2500 pages, there was a pause navigating from the site details screen to the page list, I think due to the hierarchy being processed. We'll have an opportunity to improve performance there but that behavior is not really related to this PR, and it should be a very rare issue so let's address it later.

I noted a nitpicky thing about our style guide but other than that we can :shipit:! Thank ya sir :)

[self syncPostsOfType:postType
withOptions:options
forBlog:blog
loadedPosts:@[].mutableCopy
Copy link
Member

Choose a reason for hiding this comment

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

This is super nitpicky. Our objc style guide calls for dot notation only for @proprties. Method calls in particular we like to retain the bracket syntax: [@[] mutableCopy].

DDLogError(@"Could not retrieve blog in context %@", (error ? [NSString stringWithFormat:@"with error: %@", error] : @""));
return;
}
[self mergePosts:loadedPosts.copy
Copy link
Member

Choose a reason for hiding this comment

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

And then also bracket notation here [loadedPosts copy]

@danielebogo
Copy link
Contributor Author

Thanks @aerych ! I fixed the brackets syntax and I tested it with the ~2500 pages blog! Everything works fine!

@elibud elibud merged commit 2b12f09 into develop Oct 19, 2018
@elibud elibud deleted the feature/placed-pages-pagination branch October 19, 2018 12:42
jtreanor pushed a commit that referenced this pull request Nov 7, 2018
…pagination

Feature/placed pages pagination
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants