Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #3636 from mrfelton/perf/loading
Browse files Browse the repository at this point in the history
App loading performance improvements
  • Loading branch information
mrfelton authored Oct 4, 2020
2 parents 2305ecb + d186670 commit 7d4db35
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 16 deletions.
23 changes: 10 additions & 13 deletions renderer/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const App = ({
fetchTransactions,
setModals,
initBackupService,
isSyncedToGraph,
fetchSuggestedNodes,
initTickers,
lnurlAuthParams,
Expand All @@ -60,41 +61,31 @@ const App = ({
* node data quite frequently but as time goes on the frequency is reduced to a max of PEERS_MAX_REFETCH_INTERVAL
*/
appScheduler.addTask({
task: () => fetchDescribeNetwork() && fetchPeers(),
task: () => !isSyncedToGraph && fetchDescribeNetwork(),
taskId: 'fetchNetworkData',
baseDelay: PEERS_INITIAL_REFETCH_INTERVAL,
maxDelay: PEERS_MAX_REFETCH_INTERVAL,
backoff: PEERS_REFETCH_BACKOFF_SCHEDULE,
})

appScheduler.addTask({
task: () => fetchTransactions(true),
taskId: 'fetchTransactions',
baseDelay: TX_REFETCH_INTERVAL,
})

appScheduler.addTask({
task: updateAutopilotNodeScores,
taskId: 'updateAutopilotNodeScores',
baseDelay: AUTOPILOT_SCORES_REFRESH_INTERVAL,
})

return () => {
appScheduler.removeAllTasks()
}
}, [fetchDescribeNetwork, fetchPeers, fetchTransactions, updateAutopilotNodeScores])

useEffect(() => {
// Set wallet open state.
setIsWalletOpen(true)
// fetch data from lnd.
updateAutopilotNodeScores()
initActivityHistory()
// fetch node info.
fetchPeers()
// fetch network info
fetchDescribeNetwork()
// Update autopilot node scores.
updateAutopilotNodeScores()
// fetch other application data.
fetchSuggestedNodes()
initTickers()
// initialize backup service in forceUseTokens mode to avoid
Expand All @@ -109,8 +100,13 @@ const App = ({
if (lnurlWithdrawParams && !willShowLnurlWithdrawPrompt) {
finishLnurlWithdraw()
}

return () => {
appScheduler.removeAllTasks()
}
}, [
initActivityHistory,
isSyncedToGraph,
fetchDescribeNetwork,
fetchPeers,
fetchSuggestedNodes,
Expand Down Expand Up @@ -165,6 +161,7 @@ App.propTypes = {
initBackupService: PropTypes.func.isRequired,
initTickers: PropTypes.func.isRequired,
isAppReady: PropTypes.bool.isRequired,
isSyncedToGraph: PropTypes.bool.isRequired,
lnurlAuthParams: PropTypes.object,
lnurlChannelParams: PropTypes.object,
lnurlWithdrawParams: PropTypes.object,
Expand Down
2 changes: 2 additions & 0 deletions renderer/containers/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
lnurlSelectors,
} from 'reducers/lnurl'
import { initBackupService } from 'reducers/backup'
import { infoSelectors } from 'reducers/info'
import { setModals, modalSelectors } from 'reducers/modal'
import { fetchSuggestedNodes } from 'reducers/channels'
import { initTickers } from 'reducers/ticker'
Expand All @@ -23,6 +24,7 @@ import AppErrorBoundary from './ErrorBoundary'

const mapStateToProps = state => ({
isAppReady: appSelectors.isAppReady(state),
isSyncedToGraph: infoSelectors.isSyncedToGraph(),
redirectPayReq: state.pay.redirectPayReq,
modals: modalSelectors.getModalState(state),
lnurlWithdrawParams: lnurlSelectors.lnurlWithdrawParams(state),
Expand Down
2 changes: 1 addition & 1 deletion renderer/reducers/activity/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,9 @@ export const reloadPages = () => async dispatch => {
export const initActivityHistory = () => async dispatch => {
dispatch({ type: FETCH_ACTIVITY_HISTORY })
try {
await dispatch(loadPage())
dispatch(fetchChannels())
dispatch(fetchBalance())
await dispatch(loadPage())
dispatch({ type: FETCH_ACTIVITY_HISTORY_SUCCESS })
} catch (error) {
dispatch({ type: FETCH_ACTIVITY_HISTORY_FAILURE, error })
Expand Down
13 changes: 11 additions & 2 deletions renderer/reducers/info/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,21 @@ const infoLoaded = state => state.info.infoLoaded
const hasSynced = state => state.info.hasSynced

/**
* hasSynced - Node sync state.
* isSyncedToChain - Chain sync state.
*
* @param {State} state Redux state
* @returns {boolean} Boolean indicating if node is synced
* @returns {boolean} Boolean indicating if chain is synced
*/
const isSyncedToChain = state => get(state, 'info.data.syncedToChain', false)

/**
* isSyncedToGraph - Graph sync state.
*
* @param {State} state Redux state
* @returns {boolean} Boolean indicating if node graph is synced
*/
const isSyncedToGraph = state => get(state, 'info.data.syncedToGraph', false)

/**
* version - Node version.
*
Expand Down Expand Up @@ -230,6 +238,7 @@ export default {
infoLoaded,
hasSynced,
isSyncedToChain,
isSyncedToGraph,
version,
identityPubkey,
nodeUris,
Expand Down
10 changes: 10 additions & 0 deletions renderer/reducers/peers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { grpc } from 'workers'
import { mainLog } from '@zap/utils/log'
import createReducer from '@zap/utils/createReducer'
import { updateNodeData } from 'reducers/network'

// ------------------------------------
// Initial State
Expand Down Expand Up @@ -32,6 +34,14 @@ export const fetchPeers = () => async dispatch => {
dispatch({ type: FETCH_PEERS })
try {
const { peers } = await grpc.services.Lightning.listPeers()
peers.forEach(async ({ pubKey }) => {
try {
const { node } = await grpc.services.Lightning.getNodeInfo({ pubKey })
dispatch(updateNodeData([node]))
} catch (error) {
mainLog.warn('Unable to get node info for peer %s: %s', pubKey, error)
}
})
dispatch({ type: FETCH_PEERS_SUCCESS, peers })
} catch (error) {
dispatch({ type: FETCH_PEERS_FAILURE, error })
Expand Down

0 comments on commit 7d4db35

Please sign in to comment.