ece2312ec5
## Issue `normalizeUri` | `parseURI` is expensive and has been causing sluggish operations when called repeatedly or within a loop. ## Change Since I'm not confident enough to remove the call entirely from makeSelectClaimIsMine (although I've yet to find a scenario that the uri is not already normalized), we'll try caching the calls instead. ## Results - in a simple test of toggling between 2 category pages, we saved 20ms from `parseURI` calls alone. - in a test of opening all categories one time, the memory usage remained similar. This makes sense since we removed a `makeSelect*` (which creates a selector for each call + not memoizing), and replaced that with a cached selector that's actually memoizing.
40 lines
1.6 KiB
JavaScript
40 lines
1.6 KiB
JavaScript
import { connect } from 'react-redux';
|
|
import { PAGE_SIZE } from 'constants/claim';
|
|
import {
|
|
makeSelectClaimsInChannelForPage,
|
|
makeSelectFetchingChannelClaims,
|
|
selectClaimIsMineForUri,
|
|
makeSelectTotalPagesInChannelSearch,
|
|
makeSelectClaimForUri,
|
|
} from 'redux/selectors/claims';
|
|
import { doResolveUris } from 'redux/actions/claims';
|
|
import * as SETTINGS from 'constants/settings';
|
|
import { makeSelectChannelIsMuted } from 'redux/selectors/blocked';
|
|
import { withRouter } from 'react-router';
|
|
import { selectUserVerifiedEmail } from 'redux/selectors/user';
|
|
import { makeSelectClientSetting, selectShowMatureContent } from 'redux/selectors/settings';
|
|
|
|
import ChannelContent from './view';
|
|
|
|
const select = (state, props) => {
|
|
const { search } = props.location;
|
|
const urlParams = new URLSearchParams(search);
|
|
const page = urlParams.get('page') || 0;
|
|
return {
|
|
pageOfClaimsInChannel: makeSelectClaimsInChannelForPage(props.uri, page)(state),
|
|
fetching: makeSelectFetchingChannelClaims(props.uri)(state),
|
|
totalPages: makeSelectTotalPagesInChannelSearch(props.uri, PAGE_SIZE)(state),
|
|
channelIsMine: selectClaimIsMineForUri(state, props.uri),
|
|
channelIsBlocked: makeSelectChannelIsMuted(props.uri)(state),
|
|
claim: props.uri && makeSelectClaimForUri(props.uri)(state),
|
|
isAuthenticated: selectUserVerifiedEmail(state),
|
|
showMature: selectShowMatureContent(state),
|
|
tileLayout: makeSelectClientSetting(SETTINGS.TILE_LAYOUT)(state),
|
|
};
|
|
};
|
|
|
|
const perform = (dispatch) => ({
|
|
doResolveUris: (uris, returnCachedUris) => dispatch(doResolveUris(uris, returnCachedUris)),
|
|
});
|
|
|
|
export default withRouter(connect(select, perform)(ChannelContent));
|