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.
64 lines
2.6 KiB
JavaScript
64 lines
2.6 KiB
JavaScript
import { connect } from 'react-redux';
|
|
import { doResolveUris } from 'redux/actions/claims';
|
|
import {
|
|
makeSelectClaimForUri,
|
|
selectClaimIsMineForUri,
|
|
selectFetchingMyChannels,
|
|
selectMyClaimIdsRaw,
|
|
} from 'redux/selectors/claims';
|
|
import {
|
|
selectTopLevelCommentsForUri,
|
|
makeSelectTopLevelTotalPagesForUri,
|
|
selectIsFetchingComments,
|
|
selectIsFetchingCommentsById,
|
|
selectIsFetchingReacts,
|
|
makeSelectTotalCommentsCountForUri,
|
|
selectOthersReacts,
|
|
selectMyReacts,
|
|
makeSelectCommentIdsForUri,
|
|
selectSettingsByChannelId,
|
|
selectPinnedCommentsForUri,
|
|
} from 'redux/selectors/comments';
|
|
import { doCommentReset, doCommentList, doCommentById, doCommentReactList } from 'redux/actions/comments';
|
|
import { selectActiveChannelClaim } from 'redux/selectors/app';
|
|
import CommentsList from './view';
|
|
|
|
const select = (state, props) => {
|
|
const activeChannelClaim = selectActiveChannelClaim(state);
|
|
const topLevelComments = selectTopLevelCommentsForUri(state, props.uri);
|
|
|
|
const resolvedComments =
|
|
topLevelComments && topLevelComments.length > 0
|
|
? topLevelComments.filter(({ channel_url }) => makeSelectClaimForUri(channel_url)(state) !== undefined)
|
|
: [];
|
|
|
|
return {
|
|
topLevelComments,
|
|
resolvedComments,
|
|
myChannelIds: selectMyClaimIdsRaw(state),
|
|
allCommentIds: makeSelectCommentIdsForUri(props.uri)(state),
|
|
pinnedComments: selectPinnedCommentsForUri(state, props.uri),
|
|
topLevelTotalPages: makeSelectTopLevelTotalPagesForUri(props.uri)(state),
|
|
totalComments: makeSelectTotalCommentsCountForUri(props.uri)(state),
|
|
claim: makeSelectClaimForUri(props.uri)(state),
|
|
claimIsMine: selectClaimIsMineForUri(state, props.uri),
|
|
isFetchingComments: selectIsFetchingComments(state),
|
|
isFetchingCommentsById: selectIsFetchingCommentsById(state),
|
|
isFetchingReacts: selectIsFetchingReacts(state),
|
|
fetchingChannels: selectFetchingMyChannels(state),
|
|
settingsByChannelId: selectSettingsByChannelId(state),
|
|
myReactsByCommentId: selectMyReacts(state),
|
|
othersReactsById: selectOthersReacts(state),
|
|
activeChannelId: activeChannelClaim && activeChannelClaim.claim_id,
|
|
};
|
|
};
|
|
|
|
const perform = (dispatch) => ({
|
|
fetchTopLevelComments: (uri, page, pageSize, sortBy) => dispatch(doCommentList(uri, '', page, pageSize, sortBy)),
|
|
fetchComment: (commentId) => dispatch(doCommentById(commentId)),
|
|
fetchReacts: (commentIds) => dispatch(doCommentReactList(commentIds)),
|
|
resetComments: (claimId) => dispatch(doCommentReset(claimId)),
|
|
doResolveUris: (uris) => dispatch(doResolveUris(uris, true)),
|
|
});
|
|
|
|
export default connect(select, perform)(CommentsList);
|