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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
makeSelectClaimForUri, selectClaimForUri,
selectClaimIsMineForUri, selectClaimIsMine,
selectHasChannels, selectHasChannels,
selectFetchingMyChannels, selectFetchingMyChannels,
makeSelectTagInClaimOrChannelForUri, makeSelectTagInClaimOrChannelForUri,
@ -14,15 +14,18 @@ import { doToast } from 'redux/actions/notifications';
import { selectActiveChannelClaim } from 'redux/selectors/app'; import { selectActiveChannelClaim } from 'redux/selectors/app';
import { selectSettingsByChannelId } from 'redux/selectors/comments'; import { selectSettingsByChannelId } from 'redux/selectors/comments';
const select = (state, props) => ({ const select = (state, props) => {
activeChannelClaim: selectActiveChannelClaim(state), const claim = selectClaimForUri(state, props.uri);
hasChannels: selectHasChannels(state), return {
claim: makeSelectClaimForUri(props.uri)(state), activeChannelClaim: selectActiveChannelClaim(state),
claimIsMine: selectClaimIsMineForUri(state, props.uri), hasChannels: selectHasChannels(state),
isFetchingChannels: selectFetchingMyChannels(state), claim,
settingsByChannelId: selectSettingsByChannelId(state), claimIsMine: selectClaimIsMine(state, claim),
supportDisabled: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_SUPPORT_TAG)(state), isFetchingChannels: selectFetchingMyChannels(state),
}); settingsByChannelId: selectSettingsByChannelId(state),
supportDisabled: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_SUPPORT_TAG)(state),
};
};
const perform = (dispatch, ownProps) => ({ const perform = (dispatch, ownProps) => ({
createComment: (comment, claimId, parentId, txid, payment_intent_id, environment, sticker) => 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 { doOpenModal } from 'redux/actions/app';
import { doSetPlayingUri } from 'redux/actions/content'; import { doSetPlayingUri } from 'redux/actions/content';
import { doToast } from 'redux/actions/notifications'; 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 { selectActiveChannelClaim } from 'redux/selectors/app';
import { selectModerationDelegatorsById } from 'redux/selectors/comments'; import { selectModerationDelegatorsById } from 'redux/selectors/comments';
import { selectPlayingUri } from 'redux/selectors/content'; import { selectPlayingUri } from 'redux/selectors/content';
import CommentMenuList from './view'; import CommentMenuList from './view';
const select = (state, props) => ({ const select = (state, props) => {
claim: makeSelectClaimForUri(props.uri)(state), const claim = selectClaimForUri(state, props.uri);
claimIsMine: selectClaimIsMineForUri(state, props.uri), return {
activeChannelClaim: selectActiveChannelClaim(state), claim,
playingUri: selectPlayingUri(state), claimIsMine: selectClaimIsMine(state, claim),
moderationDelegatorsById: selectModerationDelegatorsById(state), activeChannelClaim: selectActiveChannelClaim(state),
}); playingUri: selectPlayingUri(state),
moderationDelegatorsById: selectModerationDelegatorsById(state),
};
};
const perform = (dispatch) => ({ const perform = (dispatch) => ({
openModal: (modal, props) => dispatch(doOpenModal(modal, props)), openModal: (modal, props) => dispatch(doOpenModal(modal, props)),

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,19 +1,20 @@
import { connect } from 'react-redux'; 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 { makeSelectFilePartlyDownloaded } from 'redux/selectors/file_info';
import { makeSelectEditedCollectionForId } from 'redux/selectors/collections'; import { makeSelectEditedCollectionForId } from 'redux/selectors/collections';
import { makeSelectIsSubscribed } from 'redux/selectors/subscriptions'; import { makeSelectIsSubscribed } from 'redux/selectors/subscriptions';
import PreviewOverlayProperties from './view'; import PreviewOverlayProperties from './view';
const select = (state, props) => { const select = (state, props) => {
const claim = makeSelectClaimForUri(props.uri)(state); const claim = selectClaimForUri(state, props.uri);
const claimId = claim && claim.claim_id; const claimId = claim && claim.claim_id;
return { return {
claim, claim,
editedCollection: makeSelectEditedCollectionForId(claimId)(state), editedCollection: makeSelectEditedCollectionForId(claimId)(state),
downloaded: makeSelectFilePartlyDownloaded(props.uri)(state), downloaded: makeSelectFilePartlyDownloaded(props.uri)(state),
isSubscribed: makeSelectIsSubscribed(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 { connect } from 'react-redux';
import { import {
selectClaimIsMineForUri, selectClaimIsMine,
makeSelectTitleForUri, makeSelectTitleForUri,
makeSelectThumbnailForUri, makeSelectThumbnailForUri,
makeSelectCoverForUri, makeSelectCoverForUri,
selectCurrentChannelPage, selectCurrentChannelPage,
makeSelectClaimForUri, selectClaimForUri,
makeSelectClaimIsPending, makeSelectClaimIsPending,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { selectMyUnpublishedCollections } from 'redux/selectors/collections'; import { selectMyUnpublishedCollections } from 'redux/selectors/collections';
@ -17,22 +17,26 @@ import { selectMutedChannels } from 'redux/selectors/blocked';
import { doOpenModal } from 'redux/actions/app'; import { doOpenModal } from 'redux/actions/app';
import ChannelPage from './view'; import ChannelPage from './view';
const select = (state, props) => ({ const select = (state, props) => {
title: makeSelectTitleForUri(props.uri)(state), const claim = selectClaimForUri(state, props.uri);
thumbnail: makeSelectThumbnailForUri(props.uri)(state),
cover: makeSelectCoverForUri(props.uri)(state), return {
channelIsMine: selectClaimIsMineForUri(state, props.uri), title: makeSelectTitleForUri(props.uri)(state),
page: selectCurrentChannelPage(state), thumbnail: makeSelectThumbnailForUri(props.uri)(state),
claim: makeSelectClaimForUri(props.uri)(state), cover: makeSelectCoverForUri(props.uri)(state),
isSubscribed: makeSelectIsSubscribed(props.uri, true)(state), channelIsMine: selectClaimIsMine(state, claim),
blackListedOutpoints: selectBlackListedOutpoints(state), page: selectCurrentChannelPage(state),
subCount: makeSelectSubCountForUri(props.uri)(state), claim,
pending: makeSelectClaimIsPending(props.uri)(state), isSubscribed: makeSelectIsSubscribed(props.uri, true)(state),
youtubeChannels: selectYoutubeChannels(state), blackListedOutpoints: selectBlackListedOutpoints(state),
blockedChannels: selectModerationBlockList(state), subCount: makeSelectSubCountForUri(props.uri)(state),
mutedChannels: selectMutedChannels(state), pending: makeSelectClaimIsPending(props.uri)(state),
unpublishedCollections: selectMyUnpublishedCollections(state), youtubeChannels: selectYoutubeChannels(state),
}); blockedChannels: selectModerationBlockList(state),
mutedChannels: selectMutedChannels(state),
unpublishedCollections: selectMyUnpublishedCollections(state),
};
};
const perform = (dispatch) => ({ const perform = (dispatch) => ({
openModal: (modal, props) => dispatch(doOpenModal(modal, props)), openModal: (modal, props) => dispatch(doOpenModal(modal, props)),

View file

@ -5,7 +5,7 @@ import CollectionPage from './view';
import { import {
makeSelectTitleForUri, makeSelectTitleForUri,
makeSelectThumbnailForUri, makeSelectThumbnailForUri,
selectClaimIsMineForUri, selectClaimIsMine,
makeSelectClaimIsPending, makeSelectClaimIsPending,
makeSelectClaimForClaimId, makeSelectClaimForClaimId,
makeSelectChannelForClaimUri, makeSelectChannelForClaimUri,
@ -40,7 +40,7 @@ const select = (state, props) => {
isResolvingCollection: makeSelectIsResolvingCollectionForId(collectionId)(state), isResolvingCollection: makeSelectIsResolvingCollectionForId(collectionId)(state),
title: makeSelectTitleForUri(uri)(state), title: makeSelectTitleForUri(uri)(state),
thumbnail: makeSelectThumbnailForUri(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), isMyCollection: makeSelectCollectionIsMine(collectionId)(state),
claimIsPending: makeSelectClaimIsPending(uri)(state), claimIsPending: makeSelectClaimIsPending(uri)(state),
collectionHasEdits: Boolean(makeSelectEditedCollectionForId(collectionId)(state)), collectionHasEdits: Boolean(makeSelectEditedCollectionForId(collectionId)(state)),

View file

@ -8,7 +8,7 @@ import {
makeSelectIsUriResolving, makeSelectIsUriResolving,
makeSelectTotalPagesForChannel, makeSelectTotalPagesForChannel,
makeSelectTitleForUri, makeSelectTitleForUri,
selectClaimIsMineForUri, selectClaimIsMine,
makeSelectClaimIsPending, makeSelectClaimIsPending,
makeSelectClaimIsStreamPlaceholder, makeSelectClaimIsStreamPlaceholder,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
@ -77,7 +77,7 @@ const select = (state, props) => {
totalPages: makeSelectTotalPagesForChannel(uri, PAGE_SIZE)(state), totalPages: makeSelectTotalPagesForChannel(uri, PAGE_SIZE)(state),
isSubscribed: makeSelectChannelInSubscriptions(uri)(state), isSubscribed: makeSelectChannelInSubscriptions(uri)(state),
title: makeSelectTitleForUri(uri)(state), title: makeSelectTitleForUri(uri)(state),
claimIsMine: selectClaimIsMineForUri(state, uri), claimIsMine: selectClaimIsMine(state, claim),
claimIsPending: makeSelectClaimIsPending(uri)(state), claimIsPending: makeSelectClaimIsPending(uri)(state),
isLivestream: makeSelectClaimIsStreamPlaceholder(uri)(state), isLivestream: makeSelectClaimIsStreamPlaceholder(uri)(state),
collection: makeSelectCollectionForId(collectionId)(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 { DOMAIN, SIMPLE_SITE } from 'config';
import Lbry from 'lbry'; import Lbry from 'lbry';
import { doFetchChannelListMine, doFetchCollectionListMine, doCheckPendingClaims } from 'redux/actions/claims'; 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 { doFetchFileInfos } from 'redux/actions/file_info';
import { doClearSupport, doBalanceSubscribe } from 'redux/actions/wallet'; import { doClearSupport, doBalanceSubscribe } from 'redux/actions/wallet';
import { doClearPublish } from 'redux/actions/publish'; import { doClearPublish } from 'redux/actions/publish';
@ -469,8 +469,9 @@ export function doToggleSearchExpanded() {
export function doAnalyticsView(uri, timeToStart) { export function doAnalyticsView(uri, timeToStart) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const { txid, nout, claim_id: claimId } = makeSelectClaimForUri(uri)(state); const claim = selectClaimForUri(state, uri);
const claimIsMine = selectClaimIsMineForUri(state, uri); const { txid, nout, claim_id: claimId } = claim;
const claimIsMine = selectClaimIsMineForUri(state, claim);
const outpoint = `${txid}:${nout}`; const outpoint = `${txid}:${nout}`;
if (claimIsMine) { if (claimIsMine) {
@ -484,7 +485,7 @@ export function doAnalyticsView(uri, timeToStart) {
export function doAnalyticsBuffer(uri, bufferData) { export function doAnalyticsBuffer(uri, bufferData) {
return (dispatch, getState) => { return (dispatch, getState) => {
const state = getState(); const state = getState();
const claim = makeSelectClaimForUri(uri)(state); const claim = selectClaimForUri(state, uri);
const user = selectUser(state); const user = selectUser(state);
const { const {
value: { video, audio, source }, value: { video, audio, source },

View file

@ -214,6 +214,24 @@ const selectNormalizedAndVerifiedUri = createCachedSelector(
} }
)((state, rawUri) => String(rawUri)); )((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) => { export const selectClaimIsMineForUri = (state: State, rawUri: string) => {
// Not memoizing this selector because: // Not memoizing this selector because:
// (1) The workload is somewhat lightweight. // (1) The workload is somewhat lightweight.
@ -226,13 +244,7 @@ export const selectClaimIsMineForUri = (state: State, rawUri: string) => {
} }
const claimsByUri = selectClaimsByUri(state); const claimsByUri = selectClaimsByUri(state);
const myActiveClaims = selectMyActiveClaims(state); return selectClaimIsMine(state, claimsByUri && claimsByUri[uri]);
return (
claimsByUri &&
claimsByUri[uri] &&
(claimsByUri[uri].is_my_output || (claimsByUri[uri].claim_id && myActiveClaims.has(claimsByUri[uri].claim_id)))
);
}; };
// DEPRECATED - use selectClaimIsMineForUri instead. // DEPRECATED - use selectClaimIsMineForUri instead.