-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Offline Mode: Deduplicate new posts #23152
Conversation
📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
|
📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
|
@@ -541,7 +541,7 @@ class AbstractPostListViewController: UIViewController, | |||
let posts = try result.map { try coreDataStack.mainContext.existingObject(with: $0) } | |||
let hasMore = result.count >= number | |||
|
|||
return (posts, hasMore) | |||
return (posts.deduplicated(by: \.postHash), hasMore) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This leaves a period of time where database has two posts with the same postID
– invalid state. I suggest fixing it on the PostService/getPostWithID
level where it decides when to create a new or update the existing post. The app has to make sure that it keeps the local variant as it might have newer revisions at this point.
AbstractPost *post = [blog lookupPostWithID:postID inContext:self.managedObjectContext];
I suggest updating the lookup with a foreignID
(or whatever you want to call it).
I tested passing a foreign ID using the metadata
field (only tested wp.com).
Request:
{
"metadata": [
{
"key": "wp-jp-app-foreign-id",
"operation": "update",
"value": "x-coredata://ED210C7A-B958-4371-8193-2B708EB122B5/Post/p1218"
}
],
"format": "standard",
"content": "<!-- wp:paragraph -->\n<p>1</p>\n<!-- /wp:paragraph -->",
"status": "draft",
"title": "Off-04",
"type": "post",
"author": 235722583
}
Response:
{
"ID": 713,
"site_ID": 231378612,
// ...
"metadata": [
{
"id": "1782",
"key": "wp-jp-app-foreign-id",
"value": "x-coredata://ED210C7A-B958-4371-8193-2B708EB122B5/Post/p1218"
}
],
// ...
}
The list request /rest/v1.2/sites/*/posts
also return the posts with wp-jp-app-foreign-id
key.
Note: I used objectID
as an example, but it is probably the best type of ID we could send. It would probably be best to generate a UUID
, but it'll require database schema changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the fix!
I suggest fixing it on the PostService/getPostWithID level where it decides when to create a new or update the existing post
The issue is still reproducible, and this could be the right suggestion.
Those duplicated posts are created in the db and get picked up by NSFetchedResultsController (https://www.diffchecker.com/671fRofD/).
As far as I understood, the post list returned by syncPosts
is used to index iOS search and update some posts date filters but not include or exclude particular posts. So even after I removed this return statement the post list updates continued to work.
Closing this PR in favor of #23173 |
Fixes pe7hp4-N2-p2#comment-328
Description
Notes
hash
forNSManagedObject
, which is why I added thepostHash
computed variableHow to test
Precondition: you are offline
Regression Notes
Potential unintended areas of impact
n/a
What I did to test those areas of impact (or what existing automated tests I relied on)
n/a
What automated tests I added (or what prevented me from doing so)
n/a
PR submission checklist:
RELEASE-NOTES.txt
if necessary.