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

Change sites from List to Map #5531

Merged
merged 5 commits into from
Nov 11, 2016
Merged

Change sites from List to Map #5531

merged 5 commits into from
Nov 11, 2016

Conversation

darkdh
Copy link
Member

@darkdh darkdh commented Nov 10, 2016

  • 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:

fix #4879

Auditors: @bbondy, @bsclifton, @cezaraugusto

Test Plan:
Performance:

  1. Import bulk bookmarks (4000+) from other browsers (Don't merge into toolbar)
  2. The process should finish instantly
  3. Delete Import from XXX folder
  4. The process should finish instantly

Migration:

  1. Make sure session-store-1 contains the sites data before 0.12.10
  2. Lauch Brave and Close
  3. sites of session-store-1 should change from [] tp {}

fix #4879

Auditors: @bbondy, @bsclifton, @cezaraugusto

Test Plan:
Performance:
1. Import bulk bookmarks (4000+) from other browsers (Don't merge into toolbar)
2. The process should finish instantly
3. Delete Import from XXX folder
4. The process should finish instantly

Migration:
1. Make sure session-store-1 contains the sites data before 0.12.10
2. Lauch Brave and Close
3. sites of session-store-1 should change from [] tp {}
})
data.sites = sites
}

Copy link
Member

Choose a reason for hiding this comment

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

Great job with the above 😄 It's super important to have migrations for the session data

@@ -34,7 +34,8 @@ AppStore
}
}
},
sites: [{
sites: {
[siteKey]: { // Calculated by siteUtil.getSiteKey()
Copy link
Member

Choose a reason for hiding this comment

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

could you just put the format of the key? like folder specifies folderId, URLs use location/partition/folderId?

}
if (isBookmarkFolder(tags)) {
return sites.findIndex((site) => isBookmarkFolder(site.get('tags')) && site.get('folderId') === siteDetail.get('folderId'))
const folderId = siteDetail.get('folderId')
Copy link
Member

Choose a reason for hiding this comment

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

with this refactor, the tags field really isn't needed (which is nice). Because you can determine if it's a folder or not by the folderId. It might clean things up to remove it

})

if (oldSiteDetail && oldSiteDetail.get('order') !== undefined) {
site = site.set('order', oldSiteDetail.get('order'))
Copy link
Member

Choose a reason for hiding this comment

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

At some point (doesn't have to be now, something for all of us to keep in mind 😄), I think it might be worth creating util methods to help with type conversion / default values. Something like this:

const safeNumber = (value, default) => {
  const num = Number(value)
  return isNaN(num) ? default : num
}

let destinationSite = sites.get(destinationKey)
sites = sites.delete(sourceKey)
sites = sites.map((site) => {
const siteOrder = site.get('order')
Copy link
Member

Choose a reason for hiding this comment

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

Would it make sense to pull this re-ordering out to a common method?

if (!action.siteDetail.get('folderId')) {
action.siteDetail = action.siteDetail.set('folderId', siteUtil.getNextFolderId(sites))
}
appState = appState.set('sites', siteUtil.addSite(sites, action.siteDetail, action.tag))
}
Copy link
Member

Choose a reason for hiding this comment

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

Much cleaner + easier to read 😄

@bsclifton
Copy link
Member

Looks good! 👍 I left some comments with feedback. This is a great step in making the code better 😄

@darkdh
Copy link
Member Author

darkdh commented Nov 11, 2016

Thanks for the review effort @bsclifton. It has been addressed in d8d2b66

- Updated tests to be using/expecting a map (not a list)
- Updated siteUtil to return empty map where appropriate (instead of empty array)
- Removed unused method in siteUtil
- Extra error handling in siteUtil.updateSiteFavicon
- Added back some of the missing tests for updateSiteFavicon
- Update newtab > getUnpinned() to use slice (since it's a map)

Auditors: @darkdh, @cezaraugusto
@cezaraugusto
Copy link
Contributor

cezaraugusto commented Nov 11, 2016

@darkdh only issue I could found was fixed by @bsclifton (accessed sites breaking on refresh)

@bsclifton edits fixed the above but made a regression where topSites are no longer collecting favicons instantly.

Otherwise LGTM. Awesome team work!

@cezaraugusto cezaraugusto merged commit 766722a into master Nov 11, 2016
@bsclifton bsclifton deleted the sites-refactor branch November 11, 2016 20:13
@bbondy
Copy link
Member

bbondy commented Nov 12, 2016

npm run test -- --grep="auto open bookmarks toolbar for the first bookmark" is failing in automated tests for navigationBar because of this.

Also I noticed the navigation bar star icon no longer works after this. It seems to create 3 site entries for a single website. And only the third has a bookmark tag. Sites should always be unique. Since this can cause some session store corruption I'm going to revert this.

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

Successfully merging this pull request may close these issues.

long hang on Firefox import
6 participants