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

Commit 6a9a017

Browse files
authored
Merge pull request #9015 from brave/fix/slow-about-pages
Avoid iterating all sites on every about page
2 parents 8d01a21 + fa5e987 commit 6a9a017

File tree

1 file changed

+22
-7
lines changed

1 file changed

+22
-7
lines changed

app/browser/tabs.js

+22-7
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,23 @@ ipcMain.on(messages.ABOUT_COMPONENT_INITIALIZED, (e) => {
131131
})
132132
})
133133

134+
const getBookmarksData = function (state) {
135+
let bookmarkSites = new Immutable.Map()
136+
let bookmarkFolderSites = new Immutable.Map()
137+
state.get('sites').forEach((site, siteKey) => {
138+
const tags = site.get('tags')
139+
if (tags.includes(siteTags.BOOKMARK)) {
140+
bookmarkSites = bookmarkSites.set(siteKey, site)
141+
}
142+
if (tags.includes(siteTags.BOOKMARK_FOLDER)) {
143+
bookmarkFolderSites = bookmarkFolderSites.set(siteKey, site)
144+
}
145+
})
146+
const bookmarks = bookmarkSites.toList().sort(siteUtil.siteSort).toJS()
147+
const bookmarkFolders = bookmarkFolderSites.toList().sort(siteUtil.siteSort).toJS()
148+
return {bookmarks, bookmarkFolders}
149+
}
150+
134151
const updateAboutDetails = (tab, tabValue) => {
135152
const appState = appStore.getState()
136153
const url = getSourceAboutUrl(tab.getURL())
@@ -146,8 +163,6 @@ const updateAboutDetails = (tab, tabValue) => {
146163
allSiteSettings = allSiteSettings.mergeDeep(appState.get('temporarySiteSettings'))
147164
}
148165
const extensionsValue = appState.get('extensions')
149-
const bookmarks = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK)).toList().sort(siteUtil.siteSort)
150-
const bookmarkFolders = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK_FOLDER)).toList().sort(siteUtil.siteSort)
151166
const sync = appState.get('sync')
152167
const braveryDefaults = siteSettings.braveryDefaults(appState, appConfig)
153168
const history = aboutHistoryState.getHistory(appState)
@@ -170,11 +185,11 @@ const updateAboutDetails = (tab, tabValue) => {
170185
tab.send(messages.SYNC_UPDATED, sync.toJS())
171186
tab.send(messages.BRAVERY_DEFAULTS_UPDATED, braveryDefaults)
172187
tab.send(messages.EXTENSIONS_UPDATED, extensionsValue.toJS())
173-
} else if (location === 'about:bookmarks' && bookmarks) {
174-
tab.send(messages.BOOKMARKS_UPDATED, {
175-
bookmarks: bookmarks.toJS(),
176-
bookmarkFolders: bookmarkFolders.toJS()
177-
})
188+
} else if (location === 'about:bookmarks') {
189+
const bookmarksData = getBookmarksData(appState)
190+
if (bookmarksData.bookmarks) {
191+
tab.send(messages.BOOKMARKS_UPDATED, bookmarksData)
192+
}
178193
} else if (location === 'about:history') {
179194
if (!history) {
180195
appActions.populateHistory()

0 commit comments

Comments
 (0)