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

Commit 299a076

Browse files
committed
Reduce redundant siteSort to sort once and used everywhere
fix #7240 Auditors: @bbondy, @bsclifton Test Plan: 1. Import bunch of bookmarks 2. Open bookmarks of menu shouldn't affect performance 3. Open folder on bookmark toolbar shouldn't affect performance 4. Open about:bookmarks shouldn't affect performance 5. Open/Switch/Close tabs shound't affect performance
1 parent d5848c7 commit 299a076

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

app/browser/bookmarksExporter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function createBookmarkArray (sites, parentFolderId, first = true, depth = 1) {
5252

5353
if (first) payload.push(`${indentFirst}<DL><p>`)
5454

55-
filteredBookmarks.toList().sort(siteUtil.siteSort).forEach((site) => {
55+
filteredBookmarks.forEach((site) => {
5656
if (site.get('tags').includes(siteTags.BOOKMARK) && site.get('location')) {
5757
title = site.get('customTitle') || site.get('title') || site.get('location')
5858
payload.push(`${indentNext}<DT><A HREF="${site.get('location')}">${title}</A>`)

app/browser/menu.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const menuUtil = require('../common/lib/menuUtil')
2626
const {getByTabId} = require('../common/state/tabState')
2727
const getSetting = require('../../js/settings').getSetting
2828
const locale = require('../locale')
29-
const {isSiteBookmarked, siteSort} = require('../../js/state/siteUtil')
29+
const {isSiteBookmarked} = require('../../js/state/siteUtil')
3030
const tabState = require('../../app/common/state/tabState')
3131
const isDarwin = process.platform === 'darwin'
3232
const isLinux = process.platform === 'linux'
@@ -381,7 +381,7 @@ const createBookmarksSubmenu = () => {
381381
CommonMenu.exportBookmarksMenuItem()
382382
]
383383

384-
const bookmarks = menuUtil.createBookmarkTemplateItems(appStore.getState().get('sites').toList().sort(siteSort))
384+
const bookmarks = menuUtil.createBookmarkTemplateItems(appStore.getState().get('sites'))
385385
if (bookmarks.length > 0) {
386386
submenu.push(CommonMenu.separatorMenuItem)
387387
submenu = submenu.concat(bookmarks)

app/browser/reducers/sitesReducer.js

+3
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ const sitesReducer = (state, action, immutableAction) => {
4343
state = state.set('sites', siteUtil.moveSite(state.get('sites'),
4444
action.siteDetail, action.destinationDetail, false, false, true))
4545
}
46+
state = state.set('sites', state.get('sites').sort(siteUtil.siteSort))
4647
if (syncEnabled()) {
4748
state = syncUtil.updateSiteCache(state, action.destinationDetail || action.siteDetail)
4849
}
4950
break
5051
case appConstants.APP_REMOVE_SITE:
5152
const removeSiteSyncCallback = action.skipSync ? undefined : syncActions.removeSite
5253
state = state.set('sites', siteUtil.removeSite(state.get('sites'), action.siteDetail, action.tag, true, removeSiteSyncCallback))
54+
state = state.set('sites', state.get('sites').sort(siteUtil.siteSort))
5355
if (syncEnabled()) {
5456
state = syncUtil.updateSiteCache(state, action.siteDetail)
5557
}
@@ -58,6 +60,7 @@ const sitesReducer = (state, action, immutableAction) => {
5860
state = state.set('sites', siteUtil.moveSite(state.get('sites'),
5961
action.sourceDetail, action.destinationDetail, action.prepend,
6062
action.destinationIsParent, false))
63+
state = state.set('sites', state.get('sites').sort(siteUtil.siteSort))
6164
if (syncEnabled()) {
6265
state = syncUtil.updateSiteCache(state, action.destinationDetail)
6366
}

app/browser/tabs.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const settings = require('../../js/constants/settings')
1717
const {getBaseUrl, aboutUrls} = require('../../js/lib/appUrlUtil')
1818
const siteSettings = require('../../js/state/siteSettings')
1919
const messages = require('../../js/constants/messages')
20-
const siteUtil = require('../../js/state/siteUtil')
2120
const aboutHistoryState = require('../common/state/aboutHistoryState')
2221
const appStore = require('../../js/stores/appStore')
2322
const appConfig = require('../../js/constants/appConfig')
@@ -145,8 +144,8 @@ const updateAboutDetails = (tab, tabValue) => {
145144
allSiteSettings = allSiteSettings.mergeDeep(appState.get('temporarySiteSettings'))
146145
}
147146
const extensionsValue = appState.get('extensions')
148-
const bookmarks = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK)).toList().sort(siteUtil.siteSort)
149-
const bookmarkFolders = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK_FOLDER)).toList().sort(siteUtil.siteSort)
147+
const bookmarks = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK))
148+
const bookmarkFolders = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK_FOLDER))
150149
const sync = appState.get('sync')
151150
const braveryDefaults = siteSettings.braveryDefaults(appState, appConfig)
152151
const history = aboutHistoryState.getHistory(appState)
@@ -171,8 +170,8 @@ const updateAboutDetails = (tab, tabValue) => {
171170
tab.send(messages.EXTENSIONS_UPDATED, extensionsValue.toJS())
172171
} else if (location === 'about:bookmarks' && bookmarks) {
173172
tab.send(messages.BOOKMARKS_UPDATED, {
174-
bookmarks: bookmarks.toJS(),
175-
bookmarkFolders: bookmarkFolders.toJS()
173+
bookmarks: bookmarks.toList().toJS(),
174+
bookmarkFolders: bookmarkFolders.toList().toJS()
176175
})
177176
} else if (location === 'about:history') {
178177
if (!history) {

app/browser/windows.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const LocalShortcuts = require('../localShortcuts')
1212
const {getPinnedSiteProps} = require('../common/lib/windowsUtil')
1313
const {makeImmutable} = require('../common/state/immutableUtil')
1414
const {getPinnedTabsByWindowId} = require('../common/state/tabState')
15-
const {siteSort} = require('../../js/state/siteUtil')
1615
const messages = require('../../js/constants/messages')
1716
const settings = require('../../js/constants/settings')
1817
const siteTags = require('../../js/constants/siteTags')
@@ -84,7 +83,7 @@ const updatePinnedTabs = (win) => {
8483
const sitesToAdd = pinnedSites.filter((site) =>
8584
!win.__alreadyPinnedSites.find((pinned) => pinned.equals(site)))
8685

87-
sitesToAdd.sort(siteSort).forEach((site) => {
86+
sitesToAdd.forEach((site) => {
8887
win.__alreadyPinnedSites = win.__alreadyPinnedSites.add(site)
8988
appActions.createTabRequested({
9089
url: site.get('location'),

app/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const privacy = require('../js/state/privacy')
7777
const async = require('async')
7878
const settings = require('../js/constants/settings')
7979
const BookmarksExporter = require('./browser/bookmarksExporter')
80+
const siteUtil = require('../js/state/siteUtil')
8081

8182
app.commandLine.appendSwitch('enable-features', 'BlockSmallPluginContent,PreferHtmlOverPlugins')
8283

@@ -321,7 +322,10 @@ app.on('ready', () => {
321322
// For tests we always want to load default app state
322323
const loadedPerWindowState = initialState.perWindowState
323324
delete initialState.perWindowState
324-
appActions.setState(Immutable.fromJS(initialState))
325+
// Retore map order after load
326+
let state = Immutable.fromJS(initialState)
327+
state = state.set('sites', state.get('sites').sort(siteUtil.siteSort))
328+
appActions.setState(state)
325329
setImmediate(() => perWindowStateLoaded(loadedPerWindowState))
326330
})
327331

app/renderer/components/bookmarks/bookmarksToolbar.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ class BookmarksToolbar extends ImmutableComponent {
105105
contextMenus.onShowBookmarkFolderMenu(this.bookmarks, bookmark, this.activeFrame, e)
106106
}
107107
updateBookmarkData (props) {
108-
this.bookmarks = siteUtil.getBookmarks(props.sites).toList().sort(siteUtil.siteSort)
108+
// TODO(darkdh): Remove siteSort when we have shared appState
109+
this.bookmarks = siteUtil.getBookmarks(props.sites).sort(siteUtil.siteSort)
109110

110111
const noParentItems = this.bookmarks
111112
.filter((bookmark) => !bookmark.get('parentFolderId'))
@@ -150,9 +151,9 @@ class BookmarksToolbar extends ImmutableComponent {
150151
break
151152
}
152153
}
153-
this.bookmarksForToolbar = noParentItems.take(i).sort(siteUtil.siteSort)
154+
this.bookmarksForToolbar = noParentItems.take(i)
154155
// Show at most 100 items in the overflow menu
155-
this.overflowBookmarkItems = noParentItems.skip(i).take(100).sort(siteUtil.siteSort)
156+
this.overflowBookmarkItems = noParentItems.skip(i).take(100)
156157
}
157158
componentWillMount () {
158159
this.updateBookmarkData(this.props)

0 commit comments

Comments
 (0)