Skip to content

Commit

Permalink
Merge pull request LN-Zap#1045 from mrfelton/fix/throttle-fetch-channels
Browse files Browse the repository at this point in the history
perf(grpc): throttle calls to fetch channels
  • Loading branch information
JimmyMow authored Dec 8, 2018
2 parents 27f9b5e + 5434719 commit 979b88b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
15 changes: 12 additions & 3 deletions app/reducers/channels.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createSelector } from 'reselect'
import { ipcRenderer } from 'electron'
import { debounce } from 'lodash.debounce'
import throttle from 'lodash.throttle'
import { btc } from 'lib/utils'
import { requestSuggestedNodes } from 'lib/utils/api'
import db from 'store/db'
Expand Down Expand Up @@ -277,6 +277,15 @@ export const pushclosechannelstatus = () => dispatch => {
dispatch(fetchChannels())
}

/**
* Throttled dispatch to fetchChannels.
* Calls fetchChannels no more than once per second.
*/
const throttledFetchChannels = throttle(dispatch => dispatch(fetchChannels()), 1000, {
leading: true,
trailing: true
})

// IPC event for channel graph data
export const channelGraphData = (event, data) => (dispatch, getState) => {
const { info, channels } = getState()
Expand Down Expand Up @@ -309,8 +318,8 @@ export const channelGraphData = (event, data) => (dispatch, getState) => {
if (hasUpdates) {
// We can receive a lot of channel updates from channel graph subscription in a short space of time. If these
// nvolve our our channels we make a call to fetchChannels and then fetchBalances in order to refresh our channel
// and balance data. Debounce these calls so that we don't fire too many times in quick succession.
debounce(() => dispatch(fetchChannels), 1000, { leading: true, trailing: true, maxWait: 3000 })
// and balance data. Throttle these calls so that we don't attempt to fetch channels to often.
throttledFetchChannels(dispatch)
}
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@
"\\.(css|less|sass|scss)$": "identity-obj-proxy"
},
"moduleFileExtensions": [
"js", "json"
"js",
"json"
],
"moduleDirectories": [
"app",
Expand Down Expand Up @@ -313,9 +314,9 @@
"is-electron-renderer": "2.0.1",
"javascript-state-machine": "3.1.0",
"jstimezonedetect": "1.0.6",
"lodash.debounce": "4.0.8",
"lodash.get": "4.4.2",
"lodash.pick": "4.4.0",
"lodash.throttle": "4.1.1",
"prop-types": "15.6.2",
"qrcode.react": "0.8.0",
"rc-menu": "7.4.20",
Expand Down
4 changes: 2 additions & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10696,7 +10696,7 @@ lodash.clonedeep@^4.3.2:
resolved "https://registry.yarnpkg.com/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz#e23f3f9c4f8fbdde872529c1071857a086e5ccef"
integrity sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=

lodash.debounce@4.0.8, lodash.debounce@^4.0.8:
lodash.debounce@^4.0.8:
version "4.0.8"
resolved "https://registry.yarnpkg.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz#82d79bff30a67c4005ffd5e2515300ad9ca4d7af"
integrity sha1-gteb/zCmfEAF/9XiUVMArZyk168=
Expand Down Expand Up @@ -10815,7 +10815,7 @@ lodash.templatesettings@^4.0.0:
dependencies:
lodash._reinterpolate "~3.0.0"

lodash.throttle@^4.1.1:
lodash.throttle@4.1.1, lodash.throttle@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
integrity sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ=
Expand Down

0 comments on commit 979b88b

Please sign in to comment.