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

Add new autosave fields to the PostModel #1357

Merged

Conversation

maxme
Copy link
Contributor

@maxme maxme commented Aug 20, 2019

Add 3 new fields to the PostModel + migration plan, to be used in wpandroid for restoring title/content/excerpt.

Also updated the PostStore and PostRestClient to update the AutoSaveRevisionId when fetching the post list (needed to detect unhandled auto saves in the post list).

Autosave restoration logic will be done on the client side.

@maxme maxme requested a review from malinajirka August 20, 2019 12:08
@malinajirka malinajirka self-assigned this Aug 20, 2019
Copy link
Contributor

@malinajirka malinajirka left a comment

Choose a reason for hiding this comment

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

Thanks @maxme! I've left some comments. Let me know what you think.

@@ -708,7 +711,8 @@ private void handleFetchedPostList(FetchPostListResponsePayload payload) {
// will not be updated.
boolean isPostChanged =
!post.getLastModified().equals(item.lastModified)
|| !post.getStatus().equals(item.status);
|| !post.getStatus().equals(item.status)
|| item.autoSaveRevisionId > 0;
Copy link
Contributor

@malinajirka malinajirka Aug 20, 2019

Choose a reason for hiding this comment

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

Can you pls elaborate why we compare item.autoSaveRevisionId > 0 instead of comparing item.autoSaveRevisionId != post.autoSaveRevisionId? It seems the code will mark the post as "potential conflict/isPostChanged" whenever the post contains a remoteAutoSave object. Is that what we want?

Imagine the following scenario

  1. We edit a published post and leave the editor
  2. The app remote-auto-saves it
  3. We fetch the post list -> item.autoSaveRevisionId > 0 is true since the post has unpublished revision -> a conflict is detected even though the current local copy of the post is equal to the AutoSaved copy.

Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I was a bit confused, the idea was to always get the "unhandled auto save" unless we have some local modifications (which happens when you push a remote-auto-save from the app).

I'll follow your suggestion, this won't change the current behavior, but this might be less confusing if we update the logic later.

@@ -736,6 +740,7 @@ private void handleFetchedPostList(FetchPostListResponsePayload payload) {
// both locally and on the remote), so flag the local version of the Post so the
// hosting app can inform the user and the user can decide and take action
post.setRemoteLastModified(item.lastModified);
post.setAutoSaveRevisionId(item.autoSaveRevisionId);
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd suggest introducing a new field for this scenario -> something like autoSaveRemoteRevisionId or another options is to update all the auto-save fields here. As otherwise we might end up in an inconsistent state.
Eg. we would update autoSaveRevisionId but all the other fields of the AutoSave object would still contain content related to the previous revisionId. Wdyt?

Copy link
Contributor

@malinajirka malinajirka Aug 20, 2019

Choose a reason for hiding this comment

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

Btw I think we might want to remove mRemoteAutoSaveModified since we don't use it for conflict detection anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, do you see any future usage of mRemoteAutoSaveModified? For a version 2 of the conflict dialog?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sidenote: would be great to add tests for this.

Copy link
Contributor

@malinajirka malinajirka Aug 22, 2019

Choose a reason for hiding this comment

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

Sidenote: would be great to add tests for this.

We have some tests for this method

. It should be pretty straightforward to add tests for the new logic.

Ok, do you see any future usage of mRemoteAutoSaveModified? For a version 2 of the conflict dialog?

Yes, I think we'll need it for v2.

Copy link
Contributor

@malinajirka malinajirka left a comment

Choose a reason for hiding this comment

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

Thanks @maxme! I've left one comment. And as we discussed on the call my suggestion to update all the sub-fields of the autosave object wasn't ideal. I'll create an extra PR which will introduce remoteAutoSaveRevisionId and we'll update only that field instead of updating all the autoSave object subfields.

@@ -721,8 +730,7 @@ private void handleFetchedPostList(FetchPostListResponsePayload payload) {
* was updated. However, if we know the last modified date is equal to the date we have in local
* autosave object we are sure that our invocation of /autosave updated the post directly.
*/
if (isPostChanged && item.lastModified.equals(post.getAutoSaveModified())
&& item.autoSaveModified == null) {
if (isPostChanged && item.lastModified.equals(post.getAutoSaveModified())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this change intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not intentional 🤦‍♂ but I actually found why it was removed (removed a field from PostListItem). Did an extra commit (quite useless since you'll open a followup) 57cc768

Copy link
Contributor

@malinajirka malinajirka left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

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.

2 participants