Skip to content
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

Merged
merged 3 commits into from
Apr 13, 2024

Conversation

jessepinho
Copy link
Contributor

@jessepinho jessepinho commented Apr 13, 2024

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

@jessepinho jessepinho marked this pull request as ready for review April 13, 2024 03:42
@jessepinho jessepinho merged commit cd6f987 into main Apr 13, 2024
6 checks passed
@jessepinho jessepinho deleted the jessepinho/streaming-transactions-table-web-911 branch April 13, 2024 04:23
Comment on lines +17 to +41
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;
});
}
},
});
Copy link
Collaborator

@grod220 grod220 Apr 15, 2024

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?

Copy link
Contributor Author

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 🤷🏻‍♂️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not wait for all transactions to load when going to the Transacions page
3 participants