Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

refactor sync to use appStore change listener #8480

Merged
merged 1 commit into from
Apr 27, 2017
Merged

refactor sync to use appStore change listener #8480

merged 1 commit into from
Apr 27, 2017

Conversation

diracdeltas
Copy link
Member

@diracdeltas diracdeltas commented Apr 25, 2017

and only trigger sync when important site fields are modified.
fix #8415
may also fix brave/sync#31

test plan:
0. automated sync tests should pass

  1. enable sync and go to https://example.com
  2. bookmark it. you should see a message in the console indicating a record was sent.
  3. close the page and visit it again. you should not see a message in the console.
  4. unbookmark it. you should see a message in the console indicating a record was sent.
  • Submitted a ticket for my issue if one did not already exist.
  • Used Github auto-closing keywords in the commit message.
  • Added/updated tests for this change (for new code or code which already has tests).
  • Ran git rebase -i to squash commits (if needed).

Test Plan:

@diracdeltas diracdeltas added this to the 0.15.1 milestone Apr 25, 2017
@diracdeltas diracdeltas self-assigned this Apr 25, 2017
@diracdeltas diracdeltas requested a review from ayumi April 25, 2017 06:47
if (syncEnabled()) {
state = syncUtil.updateSiteCache(state, action.destinationDetail)
}
break
case appConstants.APP_APPLY_SITE_RECORDS:
Copy link
Member Author

Choose a reason for hiding this comment

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

this was moved from appStore.js to here because it is a site reducer

Copy link
Contributor

@ayumi ayumi left a comment

Choose a reason for hiding this comment

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

Test plan worked 🎉
I think this is good pending passing sync tests given the number of touched things. I couldn't get tests to run on my local dev env.

app/sync.js Outdated

// DELETES are handled in appState because the old object is no longer
// available by the time emitChanges is received
// const isDelete = diff.op === 'remove' && path.length === 3
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: commented code

@@ -219,10 +219,10 @@ const mergeSiteDetails = (oldSiteDetail, newSiteDetail, tag, folderId, order) =>
* @param tag The tag to add for this site
* See siteTags.js for supported types. No tag means just a history item
* @param originalSiteDetail If specified, use when searching site list
* @param {Function=} syncCallback specified if this change should be synced
* @param skipSync If specified, this item is not eligible for sync
Copy link
Contributor

Choose a reason for hiding this comment

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

after reading the PR a bit, it seems to me that skipSync is a flag set to inform reducers of the original cause for addSite (a browser record vs. a downloaded record). is it worth mentioning that here for clarity?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think actually we should rename it to something clearer like addedBySync since it is just keeping track of which records were downloaded by sync.

@ayumi
Copy link
Contributor

ayumi commented Apr 26, 2017

Tests are working again. Running this branch, rebased on master a8bc66b I get failures with npm run test -- --grep="^Syncing bookmarks".

@diracdeltas
Copy link
Member Author

Tests are working again. Running this branch, rebased on master a8bc66b I get failures with npm run test -- --grep="^Syncing bookmarks".

Hm, I think this PR actually uncovered a bug in brave/sync. I will open a PR there.

and only trigger sync when important site fields are modified.
fix #8415
may also fix brave/sync#31

test plan:
0. automated sync tests should pass
1. enable sync and go to https://example.com
2. bookmark it. you should see a message in the console indicating a record was sent.
3. close the page and visit it again. you should not see a message in the console.
4. unbookmark it. you should see a message in the console indicating a record was sent.
diracdeltas added a commit to brave/sync that referenced this pull request Apr 27, 2017
The previous way somtimes merged a record into record with a different objectId somehow. Using Object.values guarantees that the final number of merged records will be the same as the number of unique objectIds.

Test plan:
1. Sync to the 'rummy tarp...' group sent by slack DM.
2. You should see a bookmark folder 'f1' with two bookmarks in it; previously the bookmarks would be at the top level.
3. checkout brave/browser-laptop#8480 and run "npm run test -- --grep='^Syncing bookmarks'". the tests should pass.
@diracdeltas
Copy link
Member Author

brave/sync#84 fixed the syncing bookmark tests for me. once that is merged, i can restart the Travis job and hopefully it will pass.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants