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

Commit c631b5d

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 139662f commit c631b5d

File tree

7 files changed

+18
-12
lines changed

7 files changed

+18
-12
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
@@ -37,13 +37,15 @@ const sitesReducer = (state, action, emitChanges) => {
3737
state = state.set('sites', siteUtil.moveSite(state.get('sites'),
3838
action.siteDetail, action.destinationDetail, false, false, true))
3939
}
40+
state = state.set('sites', state.get('sites').sort(siteUtil.siteSort))
4041
if (syncEnabled()) {
4142
state = syncUtil.updateSiteCache(state, action.destinationDetail || action.siteDetail)
4243
}
4344
break
4445
case appConstants.APP_REMOVE_SITE:
4546
const removeSiteSyncCallback = action.skipSync ? undefined : syncActions.removeSite
4647
state = state.set('sites', siteUtil.removeSite(state.get('sites'), action.siteDetail, action.tag, true, removeSiteSyncCallback))
48+
state = state.set('sites', state.get('sites').sort(siteUtil.siteSort))
4749
if (syncEnabled()) {
4850
state = syncUtil.updateSiteCache(state, action.siteDetail)
4951
}
@@ -52,6 +54,7 @@ const sitesReducer = (state, action, emitChanges) => {
5254
state = state.set('sites', siteUtil.moveSite(state.get('sites'),
5355
action.sourceDetail, action.destinationDetail, action.prepend,
5456
action.destinationIsParent, false))
57+
state = state.set('sites', state.get('sites').sort(siteUtil.siteSort))
5558
if (syncEnabled()) {
5659
state = syncUtil.updateSiteCache(state, action.destinationDetail)
5760
}

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')
@@ -137,8 +136,8 @@ const updateAboutDetails = (tab, tabValue) => {
137136
allSiteSettings = allSiteSettings.mergeDeep(appState.get('temporarySiteSettings'))
138137
}
139138
const extensionsValue = appState.get('extensions')
140-
const bookmarks = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK)).toList().sort(siteUtil.siteSort)
141-
const bookmarkFolders = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK_FOLDER)).toList().sort(siteUtil.siteSort)
139+
const bookmarks = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK))
140+
const bookmarkFolders = appState.get('sites').filter((site) => site.get('tags').includes(siteTags.BOOKMARK_FOLDER))
142141
const sync = appState.get('sync')
143142
const braveryDefaults = siteSettings.braveryDefaults(appState, appConfig)
144143
const history = aboutHistoryState.getHistory(appState)
@@ -163,8 +162,8 @@ const updateAboutDetails = (tab, tabValue) => {
163162
tab.send(messages.EXTENSIONS_UPDATED, extensionsValue.toJS())
164163
} else if (location === 'about:bookmarks' && bookmarks) {
165164
tab.send(messages.BOOKMARKS_UPDATED, {
166-
bookmarks: bookmarks.toJS(),
167-
bookmarkFolders: bookmarkFolders.toJS()
165+
bookmarks: bookmarks.toList().toJS(),
166+
bookmarkFolders: bookmarkFolders.toList().toJS()
168167
})
169168
} else if (location === 'about:history' && history) {
170169
appActions.populateHistory()

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ 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+
this.bookmarks = siteUtil.getBookmarks(props.sites)
109109

110110
const noParentItems = this.bookmarks
111111
.filter((bookmark) => !bookmark.get('parentFolderId'))
@@ -150,6 +150,7 @@ class BookmarksToolbar extends ImmutableComponent {
150150
break
151151
}
152152
}
153+
// TODO(darkdh): Remove siteSort when we have shared appState
153154
this.bookmarksForToolbar = noParentItems.take(i).sort(siteUtil.siteSort)
154155
// Show at most 100 items in the overflow menu
155156
this.overflowBookmarkItems = noParentItems.skip(i).take(100).sort(siteUtil.siteSort)

0 commit comments

Comments
 (0)