-
Notifications
You must be signed in to change notification settings - Fork 17
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
Stream transactions in transactions table to avoid blocking loading #935
Stream transactions in transactions table to avoid blocking loading #935
Conversation
export const createTransactionsSlice = (): SliceCreator<TransactionsSlice> => (set, get) => ({ | ||
summaries: [], | ||
|
||
loadSummaries: async () => { | ||
set(state => { | ||
state.transactions.summaries = []; | ||
}); | ||
|
||
for await (const tx of viewClient.transactionInfo({})) { | ||
const summary = { | ||
height: Number(tx.txInfo?.height ?? 0n), | ||
hash: tx.txInfo?.id?.inner ? uint8ArrayToHex(tx.txInfo.id.inner) : 'unknown', | ||
description: getTransactionClassificationLabel(tx.txInfo?.view), | ||
}; | ||
|
||
const summaries = [...get().transactions.summaries, summary].sort( | ||
(a, b) => b.height - a.height, | ||
); | ||
|
||
set(state => { | ||
state.transactions.summaries = summaries; | ||
}); | ||
} | ||
}, | ||
}); |
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 wonder if this is better than using useStream? 🤔
useStream feels more generic and we could make it accept a transformer or create our own custom hook that wraps around that. Not sure, what do you think?
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.
Yeah, I'd considered that. The only reason I didn't is that I assumed we'd want this data in Zustand state. But, it could go either way 🤷🏻♂️
Screen.Recording.2024-04-12.at.8.40.11.PM.mov
Reviewers, what do you think of this?
@Valentine1898 pointed out in #911 that there's a delay when switching to the transactions table if you have a lot of transactions. So in this PR, I switched it to stream results, so that it's more responsive.
This results in a similar issue to what we were dealing with on the staking page, though: the page might actually take longer to load all the data, even though it feels faster, because of rendering costs.
That said, I generated nearly 200 transactions and then loaded the page, and it finished loading in under a second. So I think we're OK.
Closes #911