Skip to content

Commit

Permalink
Imporves perf of bookmark hanger
Browse files Browse the repository at this point in the history
Resolves brave#9674

Auditors: @bsclifton

Test Plan:
- have a lot of bookmarks (1k +)
- try to add a bookmark with clicking on the star
  • Loading branch information
NejcZdovc committed Jul 5, 2017
1 parent 0562bf4 commit 765c713
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/renderer/components/bookmarks/addEditBookmarkHanger.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ class AddEditBookmarkHanger extends React.Component {
props.currentDetail = currentDetail // TODO (nejc) improve, primitives only
props.originalDetail = originalDetail // TODO (nejc) improve, primitives only
props.destinationDetail = bookmarkDetail.get('destinationDetail') // TODO (nejc) improve, primitives only
props.hasBookmarks = state.get('sites').find(
props.hasBookmarks = state.get('sites').some(
(site) => siteUtil.isBookmark(site) || siteUtil.isFolder(site)
)

Expand Down
13 changes: 9 additions & 4 deletions js/state/siteUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,17 @@ module.exports.getFolder = function (sites, folderId) {
module.exports.getFolders = function (sites, folderId, parentId, labelPrefix) {
parentId = parentId || 0
let folders = []
sites.toList().sort(module.exports.siteSort).forEach((site) => {
if ((site.get('parentFolderId') || 0) === parentId && module.exports.isFolder(site)) {
sites
.filter(site => {
return (site.get('parentFolderId', 0) === parentId && module.exports.isFolder(site))
})
.toList()
.sort(module.exports.siteSort)
.forEach((site) => {
if (site.get('folderId') === folderId) {
return
}

const label = (labelPrefix || '') + (site.get('customTitle') || site.get('title'))
folders.push({
folderId: site.get('folderId'),
Expand All @@ -766,8 +772,7 @@ module.exports.getFolders = function (sites, folderId, parentId, labelPrefix) {
})
const subsites = module.exports.getFolders(sites, folderId, site.get('folderId'), (label || '') + ' / ')
folders = folders.concat(subsites)
}
})
})
return folders
}

Expand Down

0 comments on commit 765c713

Please sign in to comment.