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>
64 lines
2.8 KiB
JavaScript
64 lines
2.8 KiB
JavaScript
import { connect } from 'react-redux';
|
|
import {
|
|
selectClaimForUri,
|
|
makeSelectIsUriResolving,
|
|
selectClaimIsMine,
|
|
makeSelectClaimIsPending,
|
|
makeSelectClaimIsNsfw,
|
|
makeSelectReflectingClaimForUri,
|
|
makeSelectClaimWasPurchased,
|
|
makeSelectTitleForUri,
|
|
selectDateForUri,
|
|
} from 'redux/selectors/claims';
|
|
import { makeSelectStreamingUrlForUri } from 'redux/selectors/file_info';
|
|
import {
|
|
makeSelectCollectionIsMine,
|
|
makeSelectUrlsForCollectionId,
|
|
makeSelectIndexForUrlInCollection,
|
|
} from 'redux/selectors/collections';
|
|
|
|
import { doResolveUri } from 'redux/actions/claims';
|
|
import { doCollectionEdit } from 'redux/actions/collections';
|
|
import { doFileGet } from 'redux/actions/file';
|
|
import { selectBanStateForUri } from 'lbryinc';
|
|
import { selectShowMatureContent } from 'redux/selectors/settings';
|
|
import { makeSelectHasVisitedUri } from 'redux/selectors/content';
|
|
import { makeSelectIsSubscribed } from 'redux/selectors/subscriptions';
|
|
import ClaimPreview from './view';
|
|
import formatMediaDuration from 'util/formatMediaDuration';
|
|
|
|
const select = (state, props) => {
|
|
const claim = props.uri && selectClaimForUri(state, props.uri);
|
|
const media = claim && claim.value && (claim.value.video || claim.value.audio);
|
|
const mediaDuration = media && media.duration && formatMediaDuration(media.duration, { screenReader: true });
|
|
|
|
return {
|
|
claim,
|
|
mediaDuration,
|
|
date: props.uri && selectDateForUri(state, props.uri),
|
|
title: props.uri && makeSelectTitleForUri(props.uri)(state),
|
|
pending: props.uri && makeSelectClaimIsPending(props.uri)(state),
|
|
reflectingProgress: props.uri && makeSelectReflectingClaimForUri(props.uri)(state),
|
|
obscureNsfw: selectShowMatureContent(state) === false,
|
|
claimIsMine: props.uri && selectClaimIsMine(state, claim),
|
|
isResolvingUri: props.uri && makeSelectIsUriResolving(props.uri)(state),
|
|
isResolvingRepost: props.uri && makeSelectIsUriResolving(props.repostUrl)(state),
|
|
nsfw: props.uri && makeSelectClaimIsNsfw(props.uri)(state),
|
|
banState: selectBanStateForUri(state, props.uri),
|
|
hasVisitedUri: props.uri && makeSelectHasVisitedUri(props.uri)(state),
|
|
isSubscribed: props.uri && makeSelectIsSubscribed(props.uri, true)(state),
|
|
streamingUrl: props.uri && makeSelectStreamingUrlForUri(props.uri)(state),
|
|
wasPurchased: props.uri && makeSelectClaimWasPurchased(props.uri)(state),
|
|
isCollectionMine: makeSelectCollectionIsMine(props.collectionId)(state),
|
|
collectionUris: makeSelectUrlsForCollectionId(props.collectionId)(state),
|
|
collectionIndex: makeSelectIndexForUrlInCollection(props.uri, props.collectionId)(state),
|
|
};
|
|
};
|
|
|
|
const perform = (dispatch) => ({
|
|
resolveUri: (uri) => dispatch(doResolveUri(uri)),
|
|
getFile: (uri) => dispatch(doFileGet(uri, false)),
|
|
editCollection: (id, params) => dispatch(doCollectionEdit(id, params)),
|
|
});
|
|
|
|
export default connect(select, perform)(ClaimPreview);
|