Reduce the chain of renders when Viewer Count is updated

3 layer of components were rendered because of the viewer-count update.  Only `fileViewCount` needs the value, so let it grab from redux directly.
This commit is contained in:
infinite-persistence 2021-11-17 17:23:01 +08:00
parent 01f771c6ca
commit b69c1ec5fe
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
6 changed files with 18 additions and 21 deletions

View file

@ -8,12 +8,11 @@ import ClaimPreviewReset from 'component/claimPreviewReset';
type Props = { type Props = {
uri: string, uri: string,
livestream?: boolean, livestream?: boolean,
activeViewers?: number,
isLive?: boolean, isLive?: boolean,
}; };
function FileSubtitle(props: Props) { function FileSubtitle(props: Props) {
const { uri, livestream = false, activeViewers, isLive = false } = props; const { uri, livestream = false, isLive = false } = props;
return ( return (
<> <>
@ -21,7 +20,7 @@ function FileSubtitle(props: Props) {
<div className="file__viewdate"> <div className="file__viewdate">
{livestream ? <span>{__('Right now')}</span> : <DateTime uri={uri} show={DateTime.SHOW_DATE} />} {livestream ? <span>{__('Right now')}</span> : <DateTime uri={uri} show={DateTime.SHOW_DATE} />}
<FileViewCount uri={uri} livestream={livestream} activeViewers={activeViewers} isLive={isLive} /> <FileViewCount uri={uri} livestream={livestream} isLive={isLive} />
</div> </div>
<FileActions uri={uri} hideRepost={livestream} livestream={livestream} /> <FileActions uri={uri} hideRepost={livestream} livestream={livestream} />

View file

@ -2,18 +2,15 @@ import { connect } from 'react-redux';
import { doFetchSubCount, selectSubCountForUri } from 'lbryinc'; import { doFetchSubCount, selectSubCountForUri } from 'lbryinc';
import { selectTitleForUri, selectClaimForUri } from 'redux/selectors/claims'; import { selectTitleForUri, selectClaimForUri } from 'redux/selectors/claims';
import { makeSelectInsufficientCreditsForUri } from 'redux/selectors/content'; import { makeSelectInsufficientCreditsForUri } from 'redux/selectors/content';
import { selectViewersForId } from 'redux/selectors/livestream';
import FileTitleSection from './view'; import FileTitleSection from './view';
const select = (state, props) => { const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri); const claim = selectClaimForUri(state, props.uri);
const viewers = claim && selectViewersForId(state, claim.claim_id);
const channelClaimId = claim && claim.signing_channel ? claim.signing_channel.claim_id : undefined; const channelClaimId = claim && claim.signing_channel ? claim.signing_channel.claim_id : undefined;
const channelUri = claim && claim.signing_channel ? claim.signing_channel.canonical_url : undefined; const channelUri = claim && claim.signing_channel ? claim.signing_channel.canonical_url : undefined;
const subCount = channelUri && selectSubCountForUri(state, channelUri); const subCount = channelUri && selectSubCountForUri(state, channelUri);
return { return {
viewers,
isInsufficientCredits: makeSelectInsufficientCreditsForUri(props.uri)(state), isInsufficientCredits: makeSelectInsufficientCreditsForUri(props.uri)(state),
title: selectTitleForUri(state, props.uri), title: selectTitleForUri(state, props.uri),
channelClaimId, channelClaimId,

View file

@ -21,7 +21,6 @@ type Props = {
isNsfwBlocked: boolean, isNsfwBlocked: boolean,
livestream?: boolean, livestream?: boolean,
isLive?: boolean, isLive?: boolean,
viewers?: number,
subCount: number, subCount: number,
channelClaimId?: string, channelClaimId?: string,
fetchSubCount: (string) => void, fetchSubCount: (string) => void,
@ -35,7 +34,6 @@ function FileTitleSection(props: Props) {
isNsfwBlocked, isNsfwBlocked,
livestream = false, livestream = false,
isLive = false, isLive = false,
viewers,
subCount, subCount,
channelClaimId, channelClaimId,
fetchSubCount, fetchSubCount,
@ -66,7 +64,7 @@ function FileTitleSection(props: Props) {
body={ body={
<React.Fragment> <React.Fragment>
<ClaimInsufficientCredits uri={uri} /> <ClaimInsufficientCredits uri={uri} />
<FileSubtitle uri={uri} isLive={isLive} livestream={livestream} activeViewers={viewers} /> <FileSubtitle uri={uri} isLive={isLive} livestream={livestream} />
</React.Fragment> </React.Fragment>
} }
actions={ actions={

View file

@ -1,13 +1,18 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimForUri } from 'redux/selectors/claims'; import { selectClaimIdForUri } from 'redux/selectors/claims';
import { selectViewersForId } from 'redux/selectors/livestream';
import { doFetchViewCount, selectViewCountForUri } from 'lbryinc'; import { doFetchViewCount, selectViewCountForUri } from 'lbryinc';
import { doAnalyticsView } from 'redux/actions/app'; import { doAnalyticsView } from 'redux/actions/app';
import FileViewCount from './view'; import FileViewCount from './view';
const select = (state, props) => ({ const select = (state, props) => {
claim: makeSelectClaimForUri(props.uri)(state), const claimId = selectClaimIdForUri(state, props.uri);
return {
claimId,
viewCount: selectViewCountForUri(state, props.uri), viewCount: selectViewCountForUri(state, props.uri),
}); activeViewers: props.livestream && props.isLive && claimId ? selectViewersForId(state, claimId) : undefined,
};
};
const perform = (dispatch) => ({ const perform = (dispatch) => ({
fetchViewCount: (claimId) => dispatch(doFetchViewCount(claimId)), fetchViewCount: (claimId) => dispatch(doFetchViewCount(claimId)),

View file

@ -4,20 +4,19 @@ import React from 'react';
import HelpLink from 'component/common/help-link'; import HelpLink from 'component/common/help-link';
type Props = { type Props = {
claim: ?StreamClaim, livestream?: boolean,
isLive?: boolean,
// --- redux ---
claimId: ?string,
fetchViewCount: (string) => void, fetchViewCount: (string) => void,
fetchingViewCount: boolean,
uri: string, uri: string,
viewCount: string, viewCount: string,
livestream?: boolean,
activeViewers?: number, activeViewers?: number,
isLive?: boolean,
doAnalyticsView: (string) => void, doAnalyticsView: (string) => void,
}; };
function FileViewCount(props: Props) { function FileViewCount(props: Props) {
const { claim, uri, fetchViewCount, viewCount, livestream, activeViewers, isLive = false, doAnalyticsView } = props; const { claimId, uri, fetchViewCount, viewCount, livestream, activeViewers, isLive = false, doAnalyticsView } = props;
const claimId = claim && claim.claim_id;
React.useEffect(() => { React.useEffect(() => {
if (livestream) { if (livestream) {

View file

@ -16,7 +16,6 @@ import { parseSticker } from 'util/comments';
type Props = { type Props = {
uri: string, uri: string,
claim: ?StreamClaim, claim: ?StreamClaim,
activeViewers: number,
embed?: boolean, embed?: boolean,
doCommentSocketConnect: (string, string) => void, doCommentSocketConnect: (string, string) => void,
doCommentSocketDisconnect: (string) => void, doCommentSocketDisconnect: (string) => void,