Batch-resolves channel page query

Closes 5597: batch resolves on channel search page

Do a batch-resolve immediate after getting the results and before setting the result variable, as the latter would result in the Claim* components resolving individually.

I enabled `returnCachedClaims` -- I assumed that's a reasonable thing to do. I don't see other places use it, though, so highlighting it here.
This commit is contained in:
infinite-persistence 2021-03-05 15:10:18 +08:00 committed by Sean Yesmunt
parent 05383701af
commit c92fc2e16b
2 changed files with 13 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import {
makeSelectClaimIsMine, makeSelectClaimIsMine,
makeSelectTotalPagesInChannelSearch, makeSelectTotalPagesInChannelSearch,
makeSelectClaimForUri, makeSelectClaimForUri,
doResolveUris,
SETTINGS, SETTINGS,
} from 'lbry-redux'; } from 'lbry-redux';
import { makeSelectChannelIsMuted } from 'redux/selectors/blocked'; import { makeSelectChannelIsMuted } from 'redux/selectors/blocked';
@ -32,4 +33,8 @@ const select = (state, props) => {
}; };
}; };
export default withRouter(connect(select)(ChannelPage)); const perform = (dispatch) => ({
doResolveUris: (uris) => dispatch(doResolveUris(uris)),
});
export default withRouter(connect(select, perform)(ChannelPage));

View file

@ -30,6 +30,7 @@ type Props = {
showMature: boolean, showMature: boolean,
tileLayout: boolean, tileLayout: boolean,
viewHiddenChannels: boolean, viewHiddenChannels: boolean,
doResolveUris: (Array<string>, boolean) => void,
}; };
function ChannelContent(props: Props) { function ChannelContent(props: Props) {
@ -46,6 +47,7 @@ function ChannelContent(props: Props) {
showMature, showMature,
tileLayout, tileLayout,
viewHiddenChannels, viewHiddenChannels,
doResolveUris,
} = props; } = props;
const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0; const claimsInChannel = (claim && claim.meta.claims_in_channel) || 0;
const [searchQuery, setSearchQuery] = React.useState(''); const [searchQuery, setSearchQuery] = React.useState('');
@ -78,6 +80,11 @@ function ChannelContent(props: Props) {
return `lbry://${name}#${claimId}`; return `lbry://${name}#${claimId}`;
}); });
// Batch-resolve the urls before calling 'setSearchResults', as the
// latter will immediately cause the tiles to resolve, ending up
// calling doResolveUri one by one before the batched one.
doResolveUris(urls, true);
setSearchResults(urls); setSearchResults(urls);
}) })
.catch(() => { .catch(() => {