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.
50 lines
2 KiB
JavaScript
50 lines
2 KiB
JavaScript
import { connect } from 'react-redux';
|
|
import {
|
|
makeSelectClaimForUri,
|
|
selectClaimIsMineForUri,
|
|
selectHasChannels,
|
|
selectFetchingMyChannels,
|
|
makeSelectTagInClaimOrChannelForUri,
|
|
} from 'redux/selectors/claims';
|
|
import { CommentCreate } from './view';
|
|
import { DISABLE_SUPPORT_TAG } from 'constants/tags';
|
|
import { doCommentCreate, doFetchCreatorSettings, doCommentById } from 'redux/actions/comments';
|
|
import { doSendTip, doSendCashTip } from 'redux/actions/wallet';
|
|
import { doToast } from 'redux/actions/notifications';
|
|
import { selectActiveChannelClaim } from 'redux/selectors/app';
|
|
import { selectSettingsByChannelId } from 'redux/selectors/comments';
|
|
|
|
const select = (state, props) => ({
|
|
activeChannelClaim: selectActiveChannelClaim(state),
|
|
hasChannels: selectHasChannels(state),
|
|
claim: makeSelectClaimForUri(props.uri)(state),
|
|
claimIsMine: selectClaimIsMineForUri(state, props.uri),
|
|
isFetchingChannels: selectFetchingMyChannels(state),
|
|
settingsByChannelId: selectSettingsByChannelId(state),
|
|
supportDisabled: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_SUPPORT_TAG)(state),
|
|
});
|
|
|
|
const perform = (dispatch, ownProps) => ({
|
|
createComment: (comment, claimId, parentId, txid, payment_intent_id, environment, sticker) =>
|
|
dispatch(
|
|
doCommentCreate(
|
|
comment,
|
|
claimId,
|
|
parentId,
|
|
ownProps.uri,
|
|
ownProps.livestream,
|
|
txid,
|
|
payment_intent_id,
|
|
environment,
|
|
sticker
|
|
)
|
|
),
|
|
doFetchCreatorSettings: (channelClaimId) => dispatch(doFetchCreatorSettings(channelClaimId)),
|
|
doToast: (options) => dispatch(doToast(options)),
|
|
fetchComment: (commentId) => dispatch(doCommentById(commentId, false)),
|
|
sendCashTip: (tipParams, userParams, claimId, environment, successCallback) =>
|
|
dispatch(doSendCashTip(tipParams, false, userParams, claimId, environment, successCallback)),
|
|
sendTip: (params, callback, errorCallback) => dispatch(doSendTip(params, false, callback, errorCallback, false)),
|
|
});
|
|
|
|
export default connect(select, perform)(CommentCreate);
|