-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce API calls from certain elements by keeping global state up-to-date and caching redundant data #126
Conversation
fetchWallet() is already called in startNode aka start() in ducks/node.js
Bid and namestate data will be updated on every new block and stored globally instead of being retrieved by each component individually.
bdddabd
to
525a7e5
Compare
rebase to 525a7e5: |
https://www.youtube.com/watch?v=VI6dsMeABpU. Will review in the AM. |
TODO: Use newBlockStatus to monitor the flurry of |
LGTM. Let me know when you want a merge. |
TXs are still sorted by date but this way we can key into the TX history by txid and avoid requesting data we already have.
@mslipper added one last patchset. This replaces the Pushing this up for now, going to bang on it a bit more tomorrow and make sure it's all good. |
@@ -56,7 +56,7 @@ export default function walletReducer(state = getInitialState(), {type, payload} | |||
...state.balance | |||
}, | |||
isLocked: true, | |||
transactions: [] | |||
transactions: new Map() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious: what is the advantage of using a Map
in this context as opposed to a simple {}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PropTypes checker was throwing an error before the first update.
29a9770
to
216a858
Compare
rebase to 216a858 Remove leftover |
Closes #100
This PR reduces API calls in certain views to improve UI performance. The "Your Bids" view in particular has a table with three elements per bid: each of these elements was individually calling
getNameInfo()
on the same name! In addition, the use ofcomponentWillMount()
in certain elements to update state is insufficient since a new block event (and state update) will not trigger this method. The elements themselves should just rely on the global state being updated already.Since bids and namestates only change when new blocks connect to the chain, we only really need to gather this data once per block. The data is already stored in the global state, so all we have to do is change when it is updated.
This patch adds a new function
onNewBlock()
tobackgroundMonitor
which is executed any time adoPoll()
encounters a new block from hsd. This function gets current fee rates, gets all bids, and then iterates through all the bids getting updated namestates. This means that on every new block, UI may be a bit sluggish for a minute. A new progress indicator is added in the sidebar footer.Tested by running a bash script that opened 300 names and then bid once or twice on each name.
Future work:
getNameInfo
for ways to reduce 2 API calls (node.getNameInfo
+wallet.getAuctionInfo
) to one, or cache some data if possible.Demonstration
UI elements seem more responsive than before even when a new block is being processed. Once the new block processing is done, everything is perfectly snappy since no new API calls are made when loading/changing views.
Note the new "New Block Status" message just above the current height in the sidebar footer.