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

Commit

Permalink
Optimize top sites
Browse files Browse the repository at this point in the history
Fix #10004
  • Loading branch information
bbondy committed Jul 16, 2017
1 parent 9b80bdb commit 6c102c9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
22 changes: 19 additions & 3 deletions app/common/state/aboutNewTabState.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,35 @@ const removeDuplicateDomains = (list) => {
return false
})
}

let minCountOfTopSites
let minAccessOfTopSites
/**
* topSites are defined by users. Pinned sites are attached to their positions
* in the grid, and the non pinned indexes are populated with newly accessed sites
*/
const getTopSites = (state) => {
// remove folders; sort by visit count; enforce a max limit
const sites = (state.get('sites') ? state.get('sites').toList() : new Immutable.List())
.filter((site) => !siteUtil.isFolder(site))
.filter((site) => !siteUtil.isImportedBookmark(site))
.filter((site) => !isSourceAboutUrl(site.get('location')))
.filter((site) => !siteUtil.isFolder(site) &&
!siteUtil.isImportedBookmark(site) &&
!isSourceAboutUrl(site.get('location')) &&
(minCountOfTopSites === undefined || (site.get('count') || 0) >= minCountOfTopSites) &&
(minAccessOfTopSites === undefined || (site.get('lastAccessedTime') || 0) >= minAccessOfTopSites))
.sort(sortCountDescending)
.slice(0, aboutNewTabMaxEntries)

for (let i = 0; i < sites.size; i++) {
const count = sites.getIn([i, 'count']) || 0
const access = sites.getIn([i, 'lastAccessedTime']) || 0
if (minCountOfTopSites === undefined || count < minCountOfTopSites) {
minCountOfTopSites = count
}
if (minAccessOfTopSites === undefined || access < minAccessOfTopSites) {
minAccessOfTopSites = access
}
}

// Filter out pinned and ignored sites
let unpinnedSites = sites.filter((site) => !(isPinned(state, site) || isIgnored(state, site)))
unpinnedSites = removeDuplicateDomains(unpinnedSites)
Expand Down
18 changes: 11 additions & 7 deletions app/renderer/components/frame/frame.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,11 @@ class Frame extends React.Component {
if (this.frame.isEmpty()) {
return
}
if (e.favicons && e.favicons.length > 0) {
if (e.favicons &&
e.favicons.length > 0 &&
// Favicon changes lead to recalculation of top site data so only fire
// this when needed. Some sites update favicons very frequently.
e.favicons[0] !== this.frame.get('icon')) {
imageUtil.getWorkingImageUrl(e.favicons[0], (imageFound) => {
windowActions.setFavicon(this.frame, imageFound ? e.favicons[0] : null)
})
Expand Down Expand Up @@ -599,7 +603,7 @@ class Frame extends React.Component {
}
}

const loadEnd = (savePage, url) => {
const loadEnd = (savePage, url, inPageNav) => {
if (this.frame.isEmpty()) {
return
}
Expand All @@ -614,7 +618,7 @@ class Frame extends React.Component {

const protocol = parsedUrl.protocol
const isError = this.props.aboutDetailsErrorCode
if (!this.props.isPrivate && (protocol === 'http:' || protocol === 'https:') && !isError && savePage) {
if (!this.props.isPrivate && (protocol === 'http:' || protocol === 'https:') && !isError && savePage && !inPageNav) {
// Register the site for recent history for navigation bar
// calling with setTimeout is an ugly hack for a race condition
// with setTitle. We either need to delay this call until the title is
Expand Down Expand Up @@ -732,18 +736,18 @@ class Frame extends React.Component {
}, { passive: true })
this.webview.addEventListener('did-fail-provisional-load', (e) => {
if (e.isMainFrame) {
loadEnd(false, e.validatedURL)
loadEnd(false, e.validatedURL, false)
loadFail(e, true, e.currentURL)
}
})
this.webview.addEventListener('did-fail-load', (e) => {
if (e.isMainFrame) {
loadEnd(false, e.validatedURL)
loadEnd(false, e.validatedURL, false)
loadFail(e, false, e.validatedURL)
}
})
this.webview.addEventListener('did-finish-load', (e) => {
loadEnd(true, e.validatedURL)
loadEnd(true, e.validatedURL, false)
if (this.props.runInsecureContent) {
appActions.removeSiteSetting(this.props.origin, 'runInsecureContent', this.props.isPrivate)
}
Expand All @@ -754,7 +758,7 @@ class Frame extends React.Component {
}
if (e.isMainFrame) {
windowActions.setNavigated(e.url, this.props.frameKey, true, this.props.tabId)
loadEnd(true, e.url)
loadEnd(true, e.url, true)
}
})
this.webview.addEventListener('enter-html-full-screen', () => {
Expand Down
4 changes: 3 additions & 1 deletion js/stores/appStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,9 @@ const handleAppAction = (action) => {
break
case windowConstants.WINDOW_SET_FAVICON:
appState = siteUtil.updateSiteFavicon(appState, action.frameProps.get('location'), action.favicon)
appState = aboutNewTabState.setSites(appState, action)
if (action.frameProps.get('favicon') !== action.favicon) {
appState = aboutNewTabState.setSites(appState, action)
}
break
case appConstants.APP_RENDER_URL_TO_PDF:
const pdf = require('../../app/pdf')
Expand Down

0 comments on commit 6c102c9

Please sign in to comment.