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

Commit

Permalink
perf: limiting scheduler usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfelton committed Oct 25, 2020
1 parent 645dd43 commit d48e387
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions renderer/components/App/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,15 @@ const App = ({
willShowLnurlWithdrawPrompt,
}) => {
/**
* App scheduler / polling service setup. Add new app-wide polls here
* General app initialization.
*/
useEffect(() => {
/**
* Fetch node data on an exponentially incrementing backoff schedule so that when the app is first mounted, we fetch
* node data quite frequently but as time goes on the frequency is reduced to a max of PEERS_MAX_REFETCH_INTERVAL
*/
appScheduler.addTask({
task: () => !isSyncedToGraph && fetchDescribeNetwork(),
taskId: 'fetchNetworkData',
baseDelay: PEERS_INITIAL_REFETCH_INTERVAL,
maxDelay: PEERS_MAX_REFETCH_INTERVAL,
backoff: PEERS_REFETCH_BACKOFF_SCHEDULE,
})
appScheduler.addTask({
task: updateAutopilotNodeScores,
taskId: 'updateAutopilotNodeScores',
baseDelay: AUTOPILOT_SCORES_REFRESH_INTERVAL,
})
if (activeWalletSettings.type === 'local') {
appScheduler.addTask({
task: updateAutopilotNodeScores,
taskId: 'updateAutopilotNodeScores',
baseDelay: AUTOPILOT_SCORES_REFRESH_INTERVAL,
})
appScheduler.addTask({
task: () => fetchTransactions(true),
taskId: 'fetchTransactions',
Expand Down Expand Up @@ -101,7 +90,6 @@ const App = ({
}, [
activeWalletSettings,
initActivityHistory,
isSyncedToGraph,
fetchDescribeNetwork,
fetchPeers,
fetchSuggestedNodes,
Expand All @@ -112,6 +100,27 @@ const App = ({
updateAutopilotNodeScores,
])

/**
* Fetch node data on an exponentially incrementing backoff schedule so that when the app is first mounted, we fetch
* node data quite frequently but as time goes on the frequency is reduced to a max of PEERS_MAX_REFETCH_INTERVAL
*/
useEffect(() => {
if (isSyncedToGraph) {
appScheduler.removeTask('fetchNetworkData')
} else {
appScheduler.addTask({
task: () => fetchDescribeNetwork(),
taskId: 'fetchNetworkData',
baseDelay: PEERS_INITIAL_REFETCH_INTERVAL,
maxDelay: PEERS_MAX_REFETCH_INTERVAL,
backoff: PEERS_REFETCH_BACKOFF_SCHEDULE,
})
}
}, [isSyncedToGraph, fetchDescribeNetwork])

/**
* Lnurl handlers.
*/
useEffect(() => {
if (lnurlAuthParams && !willShowLnurlAuthPrompt) {
finishLnurlAuth()
Expand Down

0 comments on commit d48e387

Please sign in to comment.