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

Issues/3786 post list sorting #3810

Merged
merged 12 commits into from
Jun 10, 2015
Merged

Conversation

aerych
Copy link
Member

@aerych aerych commented Jun 5, 2015

Refs #3786

This PR builds on work done in #3805. The relevant changes begin in dd7fa34.

The goal is to add two new helper or "meta" properties to help with sorting posts and pages returned from an NSFetchRequest. The new properties are automatically updated in response to changes to a posts date created or its remote status.

To ensure any existing posts get the correct values set, this PR includes a core data revision, mapping model, and migration policy for posts and pages.

TESTING

Setup: Prepare a local only post in the simulator BEFORE switching to this branch. For convenience, be sure to use a blog with very view posts Follow the steps outlined in this video to create a local-only post https://cloudup.com/iOZ-BQXHqyx

Test 1:

  • Launch the simulator. Confirm there are no errors launching the app and you do not have to sign in again.
  • View the post list. The local only post should be first in the list.

Test 2:

  • Use a link conditioner to reduce your network speed. A slow connection will help you verify this is working.
  • Edit an existing post. Its easier if its near the top of the list, but not THE first one in the list.
  • Set it to publish immediately and save your changes.
  • Watch closely and confirm that it is the first post in the list when publishing.

Needs Review: @koke @astralbodies

The default postID is -1, not 0.
Shows publish immedately when the date is nil.
Shows a "Local" badge.
Shows a placeholder title if there is no title or content.
If a post or page has a revision (local changes) display the relevant bits for the revision instead of the original.
Let both Post and Page implement WPPostContentViewProvider instead of just Post by moving the relevant bits into AbstractPost.
Updates Page related views to support WPPostContentViewProvider instead of WPContentViewProvider.
Adds a core data revision: 31
Adds a new migration mapping and entity migration policy.
@aerych aerych added this to the 5.3 milestone Jun 5, 2015
@aerych
Copy link
Member Author

aerych commented Jun 5, 2015

@astralbodies Would really appreciate your eyes on the migration policy to make sure its a good approach.

NSString *key = @"date_created_gmt";
[self willChangeValueForKey:key];
[self setPrimitiveValue:date_created_gmt forKey:key];
[self didChangeValueForKey:key];
Copy link
Member

Choose a reason for hiding this comment

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

Since you're supporting KVO, I recently learned that you should register dependent keys with keyPathsForValuesAffecting*

https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/KeyValueObserving/Articles/KVODependentKeys.html#//apple_ref/doc/uid/20002179-BAJEAIEE

Copy link
Member

Choose a reason for hiding this comment

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

And I think the self.meta* = ... should be between the willChange and the didChange

Copy link
Member Author

Choose a reason for hiding this comment

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

keyPathsForValuesAffecting

Nice find.

@koke
Copy link
Member

koke commented Jun 9, 2015

I might be missing something, but the metaPublishImmediately property looks redundant. In my head, local posts is something that's there so you don't lose content if the app gets killed, so it should only ever be one or two of those. Having a second sort descriptor feels like adding more complexity than it's worth.

@astralbodies
Copy link
Contributor

@aerych This looks okay. I did add a very BASIC unit test to cover migrations from 19 through 31. This does not ensure the data is migrated properly, however. Can you update the unit test to be something similar to testMigrate27to28preservesCategories in CoreDataMigrationTests to make sure your intended behavior happens?

@aerych
Copy link
Member Author

aerych commented Jun 9, 2015

I did add a very BASIC unit test to cover migrations from 19 through 31

Awesome, thanks for that! I'll have a look at the test you mentioned.

@aerych
Copy link
Member Author

aerych commented Jun 9, 2015

I might be missing something, but the metaPublishImmediately property looks redundant

Its intended to cover the edge case when a non-local post (e.g. a draft that already has a remote) is edited to publish immediately, and encounters an error when publishing leaving it in a failed state. In this case the create date would still be nil, but the meta property would be flagged to indicate the correct sort order.

@aerych
Copy link
Member Author

aerych commented Jun 9, 2015

@astralbodies I've updated the test. Ready for another round.

@@ -0,0 +1,54 @@
#import "PostToPost30To31.h"
#import "AbstractPost.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Make sure to not use any model objects in the migration as they are only valid on the most recent model version. I'd remove this import even though its not used.

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@astralbodies
Copy link
Contributor

:shipit:

@aerych
Copy link
Member Author

aerych commented Jun 10, 2015

Thanks guys!!

aerych added a commit that referenced this pull request Jun 10, 2015
@aerych aerych merged commit 5eaeff1 into release/5.3 Jun 10, 2015
@aerych aerych deleted the issues/3786-post-list-sorting branch June 10, 2015 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants