a3398843c2
Frequently used; top in perf profile Most of the time, you already have the claim object in the current context. `selectClaimIsMineForUri` will retrieve the claim again, which is wasteful, even if it is memoized (looking up the cache still takes time). Break apart the logic and added the alternative `selectClaimIsMine` for faster lookup. Co-authored-by: infinite-persistence <inf.persistence@gmail.com>
59 lines
2.6 KiB
JavaScript
59 lines
2.6 KiB
JavaScript
import { connect } from 'react-redux';
|
|
import {
|
|
makeSelectIsUriResolving,
|
|
makeSelectThumbnailForUri,
|
|
makeSelectTitleForUri,
|
|
makeSelectChannelForClaimUri,
|
|
makeSelectClaimIsNsfw,
|
|
selectClaimIdForUri,
|
|
makeSelectClaimForClaimId,
|
|
} from 'redux/selectors/claims';
|
|
import {
|
|
makeSelectUrlsForCollectionId,
|
|
makeSelectNameForCollectionId,
|
|
makeSelectEditedCollectionForId,
|
|
makeSelectPendingCollectionForId,
|
|
makeSelectCountForCollectionId,
|
|
makeSelectIsResolvingCollectionForId,
|
|
} from 'redux/selectors/collections';
|
|
import { doFetchItemsInCollection, doCollectionDelete } from 'redux/actions/collections';
|
|
import { doResolveUri } from 'redux/actions/claims';
|
|
import { selectMutedChannels } from 'redux/selectors/blocked';
|
|
import { selectBlackListedOutpoints, selectFilteredOutpoints } from 'lbryinc';
|
|
import { selectShowMatureContent } from 'redux/selectors/settings';
|
|
import CollectionPreviewTile from './view';
|
|
|
|
const select = (state, props) => {
|
|
const collectionId = props.collectionId || (props.uri && selectClaimIdForUri(state, props.uri));
|
|
const claim = props.collectionId && makeSelectClaimForClaimId(props.collectionId)(state);
|
|
const collectionUri = props.uri || (claim && (claim.canonical_url || claim.permanent_url)) || null;
|
|
|
|
return {
|
|
collectionId,
|
|
uri: collectionUri,
|
|
collectionCount: makeSelectCountForCollectionId(collectionId)(state),
|
|
collectionName: makeSelectNameForCollectionId(collectionId)(state),
|
|
collectionItemUrls: makeSelectUrlsForCollectionId(collectionId)(state), // ForId || ForUri
|
|
editedCollection: makeSelectEditedCollectionForId(collectionId)(state),
|
|
pendingCollection: makeSelectPendingCollectionForId(collectionId)(state),
|
|
claim,
|
|
isResolvingCollectionClaims: makeSelectIsResolvingCollectionForId(collectionId)(state),
|
|
channelClaim: collectionUri && makeSelectChannelForClaimUri(collectionUri)(state),
|
|
isResolvingUri: collectionUri && makeSelectIsUriResolving(collectionUri)(state),
|
|
thumbnail: collectionUri && makeSelectThumbnailForUri(collectionUri)(state),
|
|
title: collectionUri && makeSelectTitleForUri(collectionUri)(state),
|
|
blackListedOutpoints: selectBlackListedOutpoints(state),
|
|
filteredOutpoints: selectFilteredOutpoints(state),
|
|
blockedChannelUris: selectMutedChannels(state),
|
|
showMature: selectShowMatureContent(state),
|
|
isMature: makeSelectClaimIsNsfw(collectionUri)(state),
|
|
};
|
|
};
|
|
|
|
const perform = (dispatch) => ({
|
|
resolveUri: (uri) => dispatch(doResolveUri(uri)),
|
|
resolveCollectionItems: (options) => doFetchItemsInCollection(options),
|
|
deleteCollection: (id) => dispatch(doCollectionDelete(id)),
|
|
});
|
|
|
|
export default connect(select, perform)(CollectionPreviewTile);
|