Optimize selectClaimIsMine

## Why
Frequently used; top in perf profile

## Changes
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.
This commit is contained in:
infinite-persistence 2021-11-11 12:48:10 +08:00
parent 827a08ac26
commit 0f68bad3eb
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
21 changed files with 189 additions and 134 deletions

View file

@ -3,9 +3,9 @@ import { PAGE_SIZE } from 'constants/claim';
import {
makeSelectClaimsInChannelForPage,
makeSelectFetchingChannelClaims,
selectClaimIsMineForUri,
selectClaimIsMine,
makeSelectTotalPagesInChannelSearch,
makeSelectClaimForUri,
selectClaimForUri,
} from 'redux/selectors/claims';
import { doResolveUris } from 'redux/actions/claims';
import * as SETTINGS from 'constants/settings';
@ -20,13 +20,15 @@ const select = (state, props) => {
const { search } = props.location;
const urlParams = new URLSearchParams(search);
const page = urlParams.get('page') || 0;
const claim = props.uri && selectClaimForUri(state, props.uri);
return {
pageOfClaimsInChannel: makeSelectClaimsInChannelForPage(props.uri, page)(state),
fetching: makeSelectFetchingChannelClaims(props.uri)(state),
totalPages: makeSelectTotalPagesInChannelSearch(props.uri, PAGE_SIZE)(state),
channelIsMine: selectClaimIsMineForUri(state, props.uri),
channelIsMine: selectClaimIsMine(state, claim),
channelIsBlocked: makeSelectChannelIsMuted(props.uri)(state),
claim: props.uri && makeSelectClaimForUri(props.uri)(state),
claim,
isAuthenticated: selectUserVerifiedEmail(state),
showMature: selectShowMatureContent(state),
tileLayout: makeSelectClientSetting(SETTINGS.TILE_LAYOUT)(state),

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { makeSelectClaimForUri, selectClaimIsMineForUri } from 'redux/selectors/claims';
import { selectClaimForUri, selectClaimIsMine } from 'redux/selectors/claims';
import { doCollectionEdit, doFetchItemsInCollection } from 'redux/actions/collections';
import { doPrepareEdit } from 'redux/actions/publish';
import {
@ -34,7 +34,7 @@ import ClaimPreview from './view';
import fs from 'fs';
const select = (state, props) => {
const claim = makeSelectClaimForUri(props.uri, false)(state);
const claim = selectClaimForUri(state, props.uri, false); // @KP test no repost!
const collectionId = props.collectionId;
const repostedClaim = claim && claim.reposted_claim;
const contentClaim = repostedClaim || claim;
@ -51,7 +51,7 @@ const select = (state, props) => {
contentClaim,
contentSigningChannel,
contentChannelUri,
claimIsMine: selectClaimIsMineForUri(state, props.uri),
claimIsMine: selectClaimIsMine(state, claim),
hasClaimInWatchLater: makeSelectCollectionForIdHasClaimUrl(
COLLECTIONS_CONSTS.WATCH_LATER_ID,
contentPermanentUri

View file

@ -2,7 +2,7 @@ import { connect } from 'react-redux';
import {
selectClaimForUri,
makeSelectIsUriResolving,
selectClaimIsMineForUri,
selectClaimIsMine,
makeSelectClaimIsPending,
makeSelectClaimIsNsfw,
makeSelectReflectingClaimForUri,
@ -42,7 +42,7 @@ const select = (state, props) => {
pending: props.uri && makeSelectClaimIsPending(props.uri)(state),
reflectingProgress: props.uri && makeSelectReflectingClaimForUri(props.uri)(state),
obscureNsfw: selectShowMatureContent(state) === false,
claimIsMine: props.uri && selectClaimIsMineForUri(state, props.uri),
claimIsMine: props.uri && selectClaimIsMine(state, claim),
isResolvingUri: props.uri && makeSelectIsUriResolving(props.uri)(state),
isResolvingRepost: props.uri && makeSelectIsUriResolving(props.repostUrl)(state),
nsfw: props.uri && makeSelectClaimIsNsfw(props.uri)(state),

View file

@ -1,12 +1,16 @@
import { connect } from 'react-redux';
import { selectClaimIsMineForUri, makeSelectClaimForUri } from 'redux/selectors/claims';
import { selectClaimIsMine, selectClaimForUri } from 'redux/selectors/claims';
import { makeSelectIsSubscribed } from 'redux/selectors/subscriptions';
import ClaimProperties from './view';
const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
return {
claim,
isSubscribed: makeSelectIsSubscribed(props.uri)(state),
claimIsMine: selectClaimIsMineForUri(state, props.uri),
});
claimIsMine: selectClaimIsMine(state, claim),
};
};
export default connect(select, null)(ClaimProperties);

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import CollectionContent from './view';
import { makeSelectClaimForUri, selectClaimIsMineForUri } from 'redux/selectors/claims';
import { selectClaimForUri, selectClaimIsMine } from 'redux/selectors/claims';
import {
makeSelectUrlsForCollectionId,
makeSelectNameForCollectionId,
@ -12,7 +12,7 @@ import { doToggleLoopList, doToggleShuffleList } from 'redux/actions/content';
const select = (state, props) => {
const playingUri = selectPlayingUri(state);
const playingUrl = playingUri && playingUri.uri;
const claim = makeSelectClaimForUri(playingUrl)(state);
const claim = selectClaimForUri(state, playingUrl);
const url = claim && claim.permanent_url;
const loopList = selectListLoop(state);
const loop = loopList && loopList.collectionId === props.id && loopList.loop;
@ -24,7 +24,7 @@ const select = (state, props) => {
collection: makeSelectCollectionForId(props.id)(state),
collectionUrls: makeSelectUrlsForCollectionId(props.id)(state),
collectionName: makeSelectNameForCollectionId(props.id)(state),
isMine: selectClaimIsMineForUri(state, url),
isMine: selectClaimIsMine(state, claim),
loop,
shuffle,
};

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux';
import {
makeSelectClaimForUri,
selectClaimIsMineForUri,
selectClaimForUri,
selectClaimIsMine,
selectHasChannels,
selectFetchingMyChannels,
makeSelectTagInClaimOrChannelForUri,
@ -14,15 +14,18 @@ import { doToast } from 'redux/actions/notifications';
import { selectActiveChannelClaim } from 'redux/selectors/app';
import { selectSettingsByChannelId } from 'redux/selectors/comments';
const select = (state, props) => ({
const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
return {
activeChannelClaim: selectActiveChannelClaim(state),
hasChannels: selectHasChannels(state),
claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: selectClaimIsMineForUri(state, props.uri),
claim,
claimIsMine: selectClaimIsMine(state, claim),
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) =>

View file

@ -4,19 +4,22 @@ import { doCommentPin, doCommentModAddDelegate } from 'redux/actions/comments';
import { doOpenModal } from 'redux/actions/app';
import { doSetPlayingUri } from 'redux/actions/content';
import { doToast } from 'redux/actions/notifications';
import { selectClaimIsMineForUri, makeSelectClaimForUri } from 'redux/selectors/claims';
import { selectClaimIsMine, selectClaimForUri } from 'redux/selectors/claims';
import { selectActiveChannelClaim } from 'redux/selectors/app';
import { selectModerationDelegatorsById } from 'redux/selectors/comments';
import { selectPlayingUri } from 'redux/selectors/content';
import CommentMenuList from './view';
const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: selectClaimIsMineForUri(state, props.uri),
const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
return {
claim,
claimIsMine: selectClaimIsMine(state, claim),
activeChannelClaim: selectActiveChannelClaim(state),
playingUri: selectPlayingUri(state),
moderationDelegatorsById: selectModerationDelegatorsById(state),
});
};
};
const perform = (dispatch) => ({
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import Comment from './view';
import { selectClaimIsMineForUri, makeSelectClaimForUri } from 'redux/selectors/claims';
import { selectClaimIsMine, selectClaimForUri } from 'redux/selectors/claims';
import { doResolveUri } from 'redux/actions/claims';
import { doToast } from 'redux/actions/notifications';
import { selectMyReactsForComment, selectOthersReactsForComment } from 'redux/selectors/comments';
@ -11,10 +11,11 @@ const select = (state, props) => {
const activeChannelClaim = selectActiveChannelClaim(state);
const activeChannelId = activeChannelClaim && activeChannelClaim.claim_id;
const reactionKey = activeChannelId ? `${props.commentId}:${activeChannelId}` : props.commentId;
const claim = selectClaimForUri(state, props.uri);
return {
claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: selectClaimIsMineForUri(state, props.uri),
claim,
claimIsMine: selectClaimIsMine(state, claim),
myReacts: selectMyReactsForComment(state, reactionKey),
othersReacts: selectOthersReactsForComment(state, reactionKey),
activeChannelId,

View file

@ -1,8 +1,9 @@
import { connect } from 'react-redux';
import { doResolveUris } from 'redux/actions/claims';
import {
selectClaimForUri,
makeSelectClaimForUri,
selectClaimIsMineForUri,
selectClaimIsMine,
selectFetchingMyChannels,
selectMyClaimIdsRaw,
} from 'redux/selectors/claims';
@ -24,6 +25,7 @@ import { selectActiveChannelClaim } from 'redux/selectors/app';
import CommentsList from './view';
const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
const activeChannelClaim = selectActiveChannelClaim(state);
const topLevelComments = selectTopLevelCommentsForUri(state, props.uri);
@ -40,8 +42,8 @@ const select = (state, props) => {
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),
claim,
claimIsMine: selectClaimIsMine(state, claim),
isFetchingComments: selectIsFetchingComments(state),
isFetchingCommentsById: selectIsFetchingCommentsById(state),
isFetchingReacts: selectIsFetchingReacts(state),

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux';
import {
selectClaimIsMineForUri,
makeSelectClaimForUri,
selectClaimIsMine,
selectClaimForUri,
selectHasChannels,
makeSelectClaimIsStreamPlaceholder,
makeSelectTagInClaimOrChannelForUri,
@ -17,9 +17,12 @@ import fs from 'fs';
import FileActions from './view';
import { makeSelectFileRenderModeForUri } from 'redux/selectors/content';
const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: selectClaimIsMineForUri(state, props.uri),
const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
return {
claim,
claimIsMine: selectClaimIsMine(state, claim),
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
renderMode: makeSelectFileRenderModeForUri(props.uri)(state),
costInfo: makeSelectCostInfoForUri(props.uri)(state),
@ -27,7 +30,8 @@ const select = (state, props) => ({
isLivestreamClaim: makeSelectClaimIsStreamPlaceholder(props.uri)(state),
reactionsDisabled: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_COMMENTS_TAG)(state),
streamingUrl: makeSelectStreamingUrlForUri(props.uri)(state),
});
};
};
const perform = (dispatch) => ({
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),

View file

@ -1,17 +1,21 @@
import { connect } from 'react-redux';
import { makeSelectClaimForUri, makeSelectMetadataForUri, selectClaimIsMineForUri } from 'redux/selectors/claims';
import { selectClaimForUri, makeSelectMetadataForUri, selectClaimIsMine } from 'redux/selectors/claims';
import { makeSelectPendingAmountByUri } from 'redux/selectors/wallet';
import { doOpenModal } from 'redux/actions/app';
import { selectUser } from 'redux/selectors/user';
import FileDescription from './view';
const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: selectClaimIsMineForUri(state, props.uri),
const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
return {
claim,
claimIsMine: selectClaimIsMine(state, claim),
metadata: makeSelectMetadataForUri(props.uri)(state),
user: selectUser(state),
pendingAmount: makeSelectPendingAmountByUri(props.uri)(state),
});
};
};
export default connect(select, {
doOpenModal,

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux';
import { selectClaimIsMineForUri, makeSelectClaimForUri, makeSelectClaimWasPurchased } from 'redux/selectors/claims';
import { selectClaimIsMine, selectClaimForUri, makeSelectClaimWasPurchased } from 'redux/selectors/claims';
import {
makeSelectFileInfoForUri,
makeSelectDownloadingForUri,
@ -11,16 +11,20 @@ import { doOpenModal, doAnalyticsView } from 'redux/actions/app';
import { doSetPlayingUri, doPlayUri } from 'redux/actions/content';
import FileDownloadLink from './view';
const select = (state, props) => ({
const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
return {
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
downloading: makeSelectDownloadingForUri(props.uri)(state),
loading: makeSelectLoadingForUri(props.uri)(state),
claimIsMine: selectClaimIsMineForUri(state, props.uri),
claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: selectClaimIsMine(state, claim),
claim,
costInfo: makeSelectCostInfoForUri(props.uri)(state),
claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state),
streamingUrl: makeSelectStreamingUrlForUri(props.uri)(state),
});
};
};
const perform = (dispatch) => ({
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),

View file

@ -1,14 +1,18 @@
import { connect } from 'react-redux';
import { makeSelectClaimForUri, makeSelectClaimWasPurchased, selectClaimIsMineForUri } from 'redux/selectors/claims';
import { selectClaimForUri, makeSelectClaimWasPurchased, selectClaimIsMine } from 'redux/selectors/claims';
import { makeSelectCostInfoForUri, doFetchCostInfoForUri, makeSelectFetchingCostInfoForUri } from 'lbryinc';
import FilePrice from './view';
const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: selectClaimIsMineForUri(state, props.uri),
const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
return {
claim,
claimIsMine: selectClaimIsMine(state, claim),
claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state),
costInfo: makeSelectCostInfoForUri(props.uri)(state),
fetching: makeSelectFetchingCostInfoForUri(props.uri)(state),
});
};
};
export default connect(select, { doFetchCostInfoForUri })(FilePrice);

View file

@ -1,9 +1,9 @@
import { connect } from 'react-redux';
import {
makeSelectClaimForUri,
selectClaimForUri,
makeSelectContentTypeForUri,
makeSelectMetadataForUri,
selectClaimIsMineForUri,
selectClaimIsMine,
} from 'redux/selectors/claims';
import { makeSelectPendingAmountByUri } from 'redux/selectors/wallet';
import { makeSelectFileInfoForUri } from 'redux/selectors/file_info';
@ -12,15 +12,19 @@ import { doOpenModal } from 'redux/actions/app';
import FileValues from './view';
const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state),
const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
return {
claim,
contentType: makeSelectContentTypeForUri(props.uri)(state),
fileInfo: makeSelectFileInfoForUri(props.uri)(state),
metadata: makeSelectMetadataForUri(props.uri)(state),
user: selectUser(state),
pendingAmount: makeSelectPendingAmountByUri(props.uri)(state),
claimIsMine: selectClaimIsMineForUri(state, props.uri),
});
claimIsMine: selectClaimIsMine(state, claim),
};
};
const perform = (dispatch) => ({
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),

View file

@ -1,9 +1,9 @@
import { connect } from 'react-redux';
import {
selectClaimIsMineForUri,
selectClaimIsMine,
makeSelectTitleForUri,
makeSelectThumbnailForUri,
makeSelectClaimForUri,
selectClaimForUri,
makeSelectIsUriResolving,
makeSelectMetadataItemForUri,
} from 'redux/selectors/claims';
@ -12,13 +12,15 @@ import { selectBlackListedOutpoints } from 'lbryinc';
import PreviewLink from './view';
const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
return {
uri: props.uri,
claim: makeSelectClaimForUri(props.uri)(state),
claim,
title: makeSelectTitleForUri(props.uri)(state),
thumbnail: makeSelectThumbnailForUri(props.uri)(state),
description: makeSelectMetadataItemForUri(props.uri, 'description')(state),
channelIsMine: selectClaimIsMineForUri(state, props.uri),
channelIsMine: selectClaimIsMine(state, claim),
isResolvingUri: makeSelectIsUriResolving(props.uri)(state),
blackListedOutpoints: selectBlackListedOutpoints(state),
};

View file

@ -1,19 +1,20 @@
import { connect } from 'react-redux';
import { selectClaimIsMineForUri, makeSelectClaimForUri } from 'redux/selectors/claims';
import { selectClaimIsMine, selectClaimForUri } from 'redux/selectors/claims';
import { makeSelectFilePartlyDownloaded } from 'redux/selectors/file_info';
import { makeSelectEditedCollectionForId } from 'redux/selectors/collections';
import { makeSelectIsSubscribed } from 'redux/selectors/subscriptions';
import PreviewOverlayProperties from './view';
const select = (state, props) => {
const claim = makeSelectClaimForUri(props.uri)(state);
const claim = selectClaimForUri(state, props.uri);
const claimId = claim && claim.claim_id;
return {
claim,
editedCollection: makeSelectEditedCollectionForId(claimId)(state),
downloaded: makeSelectFilePartlyDownloaded(props.uri)(state),
isSubscribed: makeSelectIsSubscribed(props.uri)(state),
claimIsMine: selectClaimIsMineForUri(state, props.uri),
claimIsMine: selectClaimIsMine(state, claim),
};
};

View file

@ -1,11 +1,11 @@
import { connect } from 'react-redux';
import {
selectClaimIsMineForUri,
selectClaimIsMine,
makeSelectTitleForUri,
makeSelectThumbnailForUri,
makeSelectCoverForUri,
selectCurrentChannelPage,
makeSelectClaimForUri,
selectClaimForUri,
makeSelectClaimIsPending,
} from 'redux/selectors/claims';
import { selectMyUnpublishedCollections } from 'redux/selectors/collections';
@ -17,13 +17,16 @@ import { selectMutedChannels } from 'redux/selectors/blocked';
import { doOpenModal } from 'redux/actions/app';
import ChannelPage from './view';
const select = (state, props) => ({
const select = (state, props) => {
const claim = selectClaimForUri(state, props.uri);
return {
title: makeSelectTitleForUri(props.uri)(state),
thumbnail: makeSelectThumbnailForUri(props.uri)(state),
cover: makeSelectCoverForUri(props.uri)(state),
channelIsMine: selectClaimIsMineForUri(state, props.uri),
channelIsMine: selectClaimIsMine(state, claim),
page: selectCurrentChannelPage(state),
claim: makeSelectClaimForUri(props.uri)(state),
claim,
isSubscribed: makeSelectIsSubscribed(props.uri, true)(state),
blackListedOutpoints: selectBlackListedOutpoints(state),
subCount: makeSelectSubCountForUri(props.uri)(state),
@ -32,7 +35,8 @@ const select = (state, props) => ({
blockedChannels: selectModerationBlockList(state),
mutedChannels: selectMutedChannels(state),
unpublishedCollections: selectMyUnpublishedCollections(state),
});
};
};
const perform = (dispatch) => ({
openModal: (modal, props) => dispatch(doOpenModal(modal, props)),

View file

@ -5,7 +5,7 @@ import CollectionPage from './view';
import {
makeSelectTitleForUri,
makeSelectThumbnailForUri,
selectClaimIsMineForUri,
selectClaimIsMine,
makeSelectClaimIsPending,
makeSelectClaimForClaimId,
makeSelectChannelForClaimUri,
@ -40,7 +40,7 @@ const select = (state, props) => {
isResolvingCollection: makeSelectIsResolvingCollectionForId(collectionId)(state),
title: makeSelectTitleForUri(uri)(state),
thumbnail: makeSelectThumbnailForUri(uri)(state),
isMyClaim: selectClaimIsMineForUri(state, uri), // or collection is mine?
isMyClaim: selectClaimIsMine(state, claim), // or collection is mine?
isMyCollection: makeSelectCollectionIsMine(collectionId)(state),
claimIsPending: makeSelectClaimIsPending(uri)(state),
collectionHasEdits: Boolean(makeSelectEditedCollectionForId(collectionId)(state)),

View file

@ -8,7 +8,7 @@ import {
makeSelectIsUriResolving,
makeSelectTotalPagesForChannel,
makeSelectTitleForUri,
selectClaimIsMineForUri,
selectClaimIsMine,
makeSelectClaimIsPending,
makeSelectClaimIsStreamPlaceholder,
} from 'redux/selectors/claims';
@ -77,7 +77,7 @@ const select = (state, props) => {
totalPages: makeSelectTotalPagesForChannel(uri, PAGE_SIZE)(state),
isSubscribed: makeSelectChannelInSubscriptions(uri)(state),
title: makeSelectTitleForUri(uri)(state),
claimIsMine: selectClaimIsMineForUri(state, uri),
claimIsMine: selectClaimIsMine(state, claim),
claimIsPending: makeSelectClaimIsPending(uri)(state),
isLivestream: makeSelectClaimIsStreamPlaceholder(uri)(state),
collection: makeSelectCollectionForId(collectionId)(state),

View file

@ -12,7 +12,7 @@ import * as SHARED_PREFERENCES from 'constants/shared_preferences';
import { DOMAIN, SIMPLE_SITE } from 'config';
import Lbry from 'lbry';
import { doFetchChannelListMine, doFetchCollectionListMine, doCheckPendingClaims } from 'redux/actions/claims';
import { makeSelectClaimForUri, selectClaimIsMineForUri, selectMyChannelClaims } from 'redux/selectors/claims';
import { selectClaimForUri, selectClaimIsMineForUri, selectMyChannelClaims } from 'redux/selectors/claims';
import { doFetchFileInfos } from 'redux/actions/file_info';
import { doClearSupport, doBalanceSubscribe } from 'redux/actions/wallet';
import { doClearPublish } from 'redux/actions/publish';
@ -469,8 +469,9 @@ export function doToggleSearchExpanded() {
export function doAnalyticsView(uri, timeToStart) {
return (dispatch, getState) => {
const state = getState();
const { txid, nout, claim_id: claimId } = makeSelectClaimForUri(uri)(state);
const claimIsMine = selectClaimIsMineForUri(state, uri);
const claim = selectClaimForUri(state, uri);
const { txid, nout, claim_id: claimId } = claim;
const claimIsMine = selectClaimIsMineForUri(state, claim);
const outpoint = `${txid}:${nout}`;
if (claimIsMine) {
@ -484,7 +485,7 @@ export function doAnalyticsView(uri, timeToStart) {
export function doAnalyticsBuffer(uri, bufferData) {
return (dispatch, getState) => {
const state = getState();
const claim = makeSelectClaimForUri(uri)(state);
const claim = selectClaimForUri(state, uri);
const user = selectUser(state);
const {
value: { video, audio, source },

View file

@ -214,6 +214,24 @@ const selectNormalizedAndVerifiedUri = createCachedSelector(
}
)((state, rawUri) => String(rawUri));
export const selectClaimIsMine = (state: State, claim: ?Claim) => {
if (claim) {
// The original code seems to imply that 'is_my_output' could be false even
// when it is yours and there is a need to double-check with 'myActiveClaims'.
// I'm retaining that logic. Otherwise, we could have just return
// is_my_output directly when it is defined and skip the fallback.
if (claim.is_my_output) {
return true;
} else {
// 'is_my_output' is false or undefined.
const myActiveClaims = selectMyActiveClaims(state);
return claim.claim_id && myActiveClaims.has(claim.claim_id);
}
} else {
return false;
}
};
export const selectClaimIsMineForUri = (state: State, rawUri: string) => {
// Not memoizing this selector because:
// (1) The workload is somewhat lightweight.
@ -226,13 +244,7 @@ export const selectClaimIsMineForUri = (state: State, rawUri: string) => {
}
const claimsByUri = selectClaimsByUri(state);
const myActiveClaims = selectMyActiveClaims(state);
return (
claimsByUri &&
claimsByUri[uri] &&
(claimsByUri[uri].is_my_output || (claimsByUri[uri].claim_id && myActiveClaims.has(claimsByUri[uri].claim_id)))
);
return selectClaimIsMine(state, claimsByUri && claimsByUri[uri]);
};
// DEPRECATED - use selectClaimIsMineForUri instead.