lbry-desktop/ui/page/discover/index.js
jessopb a3398843c2
Optimize selectClaimIsMine (#7370)
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>
2021-12-31 12:52:26 -05:00

29 lines
1.1 KiB
JavaScript

import * as CS from 'constants/claim_search';
import { connect } from 'react-redux';
import { doResolveUri } from 'redux/actions/claims';
import { selectClaimForUri } from 'redux/selectors/claims';
import * as SETTINGS from 'constants/settings';
import { selectUserVerifiedEmail } from 'redux/selectors/user';
import { selectFollowedTags } from 'redux/selectors/tags';
import { doToggleTagFollowDesktop } from 'redux/actions/tags';
import { makeSelectClientSetting } from 'redux/selectors/settings';
import Tags from './view';
const select = (state, props) => {
const urlParams = new URLSearchParams(props.location.search);
const repostedUriInUrl = urlParams.get(CS.REPOSTED_URI_KEY);
const repostedUri = repostedUriInUrl ? decodeURIComponent(repostedUriInUrl) : undefined;
return {
followedTags: selectFollowedTags(state),
repostedUri: repostedUri,
repostedClaim: repostedUri ? selectClaimForUri(state, repostedUri) : null,
isAuthenticated: selectUserVerifiedEmail(state),
tileLayout: makeSelectClientSetting(SETTINGS.TILE_LAYOUT)(state),
};
};
export default connect(select, {
doToggleTagFollowDesktop,
doResolveUri,
})(Tags);