-
Notifications
You must be signed in to change notification settings - Fork 148
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
feat: implement queries throttle for switch account component #5062
Conversation
b54a852
to
c42e1d2
Compare
src/app/features/switch-account-drawer/components/switch-account-list.tsx
Outdated
Show resolved
Hide resolved
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.
I think adding the debounce directly to the hooks breaks the SRP, and generally makes them more complicated than they should be. Perhaps there might be better ways to handle adding a delay before requesting directly in the hook?
The main scenario I think about is the switch accounts lists. If a user scrolls down 300 accounts, we shouldn't queue up 300x balance and 300x bns name requests.
I reckon there are two mechanisms we could alternatively use to ensure that requests that aren't needed, don't get triggered
- Client side rate limiting
We use https://github.com/jhurliman/node-rate-limiter to ensure that we don't fire too many requests at once. These could be configured to trigger substantially less than the actual RPM, just to ensure we don't use too much. If a request is triggered and added to the queue then the component dismounts before the request is made, we use the AbortController to cancel the promise (and could even add back one unspent request to the rate limtier) - Component tree debounce.
Another way to delay the request could be internal to the account item component. We could write code where we only render the component that has the query hook, 1second after render. This way, the request is never made until the component mounts. This is the same principal as what you've built here, but implemented in a way where we don't change the query hook implementatoin.
c42e1d2
to
4fce13e
Compare
cd1142d
to
b01dd24
Compare
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.
If I have a request queued by the rate limiter, and the component dismounts, what happens?
src/app/features/collectibles/components/bitcoin/inscription.tsx
Outdated
Show resolved
Hide resolved
src/app/features/collectibles/components/bitcoin/inscription.tsx
Outdated
Show resolved
Hide resolved
@314159265359879 want to QA this one by trying to "break" it with wallets that have lots of accounts and assets? |
it looks like the coingecko API issue (error 403) was related to IP restrictions, please ignore. I don't see it now that I switched to another IP. |
bf0b234
to
6d18d64
Compare
@314159265359879 wonder if you could test latest build please |
d5e474c
to
675955a
Compare
d1fb2ff
to
d2c0b7a
Compare
31d9b12
to
5c07103
Compare
@@ -2,11 +2,21 @@ import { memo } from 'react'; | |||
|
|||
import { styled } from 'leather-styles/jsx'; | |||
|
|||
import { shimmerStyles } from '../../../../theme/global/shimmer-styles'; |
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.
At some pt we should add an alias for theme
folder.
@alter-eggo I downloaded the latest build here ...none of my Stacks NFTs are loading. 🤔 |
5c07103
to
6ab31f4
Compare
@fbwoolf thanks for testing! fixed |
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.
Great stuff @alter-eggo, just tried this out and works very well. Maybe we'll need to fine-tune some of the priority settings later, but this should already be such a huge improvement. Look forward to checking 429 errors pre/post these changes.
src/app/pages/select-network/components/network-list-item.layout.tsx
Outdated
Show resolved
Hide resolved
6ab31f4
to
6c5eb45
Compare
Does this apply to "Select account" for the recipient field of the send form as well? |
This pr throttles all balances queries on switch account list component, to prevent 429 errors