selectClaimIsMineForUri to replace makeSelectClaimIsMine

## 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.
This commit is contained in:
infinite-persistence 2021-11-10 10:30:03 +08:00 committed by infinite-persistence
parent 97b9b733c6
commit ece2312ec5
28 changed files with 92 additions and 58 deletions

View file

@ -3,7 +3,7 @@ import { PAGE_SIZE } from 'constants/claim';
import { import {
makeSelectClaimsInChannelForPage, makeSelectClaimsInChannelForPage,
makeSelectFetchingChannelClaims, makeSelectFetchingChannelClaims,
makeSelectClaimIsMine, selectClaimIsMineForUri,
makeSelectTotalPagesInChannelSearch, makeSelectTotalPagesInChannelSearch,
makeSelectClaimForUri, makeSelectClaimForUri,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
@ -24,7 +24,7 @@ const select = (state, props) => {
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: makeSelectClaimIsMine(props.uri)(state), channelIsMine: selectClaimIsMineForUri(state, props.uri),
channelIsBlocked: makeSelectChannelIsMuted(props.uri)(state), channelIsBlocked: makeSelectChannelIsMuted(props.uri)(state),
claim: props.uri && makeSelectClaimForUri(props.uri)(state), claim: props.uri && makeSelectClaimForUri(props.uri)(state),
isAuthenticated: selectUserVerifiedEmail(state), isAuthenticated: selectUserVerifiedEmail(state),

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimForUri, makeSelectClaimIsMine } from 'redux/selectors/claims'; import { makeSelectClaimForUri, selectClaimIsMineForUri } 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 {
@ -51,7 +51,7 @@ const select = (state, props) => {
contentClaim, contentClaim,
contentSigningChannel, contentSigningChannel,
contentChannelUri, contentChannelUri,
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
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,
makeSelectClaimIsMine, selectClaimIsMineForUri,
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 && makeSelectClaimIsMine(props.uri)(state), claimIsMine: props.uri && selectClaimIsMineForUri(state, props.uri),
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,6 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { selectActiveChannelClaim } from 'redux/selectors/app'; import { selectActiveChannelClaim } from 'redux/selectors/app';
import { makeSelectClaimIsMine } from 'redux/selectors/claims'; import { selectClaimIsMineForUri } from 'redux/selectors/claims';
import { doToast } from 'redux/actions/notifications'; import { doToast } from 'redux/actions/notifications';
import ClaimPreviewReset from './view'; import ClaimPreviewReset from './view';
@ -9,7 +9,7 @@ const select = (state, props) => {
return { return {
channelName, channelName,
channelId, channelId,
claimIsMine: props.uri && makeSelectClaimIsMine(props.uri)(state), claimIsMine: props.uri && selectClaimIsMineForUri(state, props.uri),
}; };
}; };

View file

@ -1,12 +1,12 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimIsMine, makeSelectClaimForUri } from 'redux/selectors/claims'; import { selectClaimIsMineForUri, makeSelectClaimForUri } 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), claim: makeSelectClaimForUri(props.uri)(state),
isSubscribed: makeSelectIsSubscribed(props.uri)(state), isSubscribed: makeSelectIsSubscribed(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
}); });
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, makeSelectClaimIsMine } from 'redux/selectors/claims'; import { makeSelectClaimForUri, selectClaimIsMineForUri } from 'redux/selectors/claims';
import { import {
makeSelectUrlsForCollectionId, makeSelectUrlsForCollectionId,
makeSelectNameForCollectionId, makeSelectNameForCollectionId,
@ -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: makeSelectClaimIsMine(url)(state), isMine: selectClaimIsMineForUri(state, url),
loop, loop,
shuffle, shuffle,
}; };

View file

@ -1,7 +1,7 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
makeSelectClaimForUri, makeSelectClaimForUri,
makeSelectClaimIsMine, selectClaimIsMineForUri,
selectHasChannels, selectHasChannels,
selectFetchingMyChannels, selectFetchingMyChannels,
makeSelectTagInClaimOrChannelForUri, makeSelectTagInClaimOrChannelForUri,
@ -18,7 +18,7 @@ const select = (state, props) => ({
activeChannelClaim: selectActiveChannelClaim(state), activeChannelClaim: selectActiveChannelClaim(state),
hasChannels: selectHasChannels(state), hasChannels: selectHasChannels(state),
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
isFetchingChannels: selectFetchingMyChannels(state), isFetchingChannels: selectFetchingMyChannels(state),
settingsByChannelId: selectSettingsByChannelId(state), settingsByChannelId: selectSettingsByChannelId(state),
supportDisabled: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_SUPPORT_TAG)(state), supportDisabled: makeSelectTagInClaimOrChannelForUri(props.uri, DISABLE_SUPPORT_TAG)(state),

View file

@ -4,7 +4,7 @@ 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 { makeSelectClaimIsMine, makeSelectClaimForUri } from 'redux/selectors/claims'; import { selectClaimIsMineForUri, makeSelectClaimForUri } 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';
@ -12,7 +12,7 @@ import CommentMenuList from './view';
const select = (state, props) => ({ const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
activeChannelClaim: selectActiveChannelClaim(state), activeChannelClaim: selectActiveChannelClaim(state),
playingUri: selectPlayingUri(state), playingUri: selectPlayingUri(state),
moderationDelegatorsById: selectModerationDelegatorsById(state), moderationDelegatorsById: selectModerationDelegatorsById(state),

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 { makeSelectClaimIsMine, makeSelectClaimForUri } from 'redux/selectors/claims'; import { selectClaimIsMineForUri, makeSelectClaimForUri } 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';
@ -14,7 +14,7 @@ const select = (state, props) => {
return { return {
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
myReacts: selectMyReactsForComment(state, reactionKey), myReacts: selectMyReactsForComment(state, reactionKey),
othersReacts: selectOthersReactsForComment(state, reactionKey), othersReacts: selectOthersReactsForComment(state, reactionKey),
activeChannelId, activeChannelId,

View file

@ -2,7 +2,7 @@ import { connect } from 'react-redux';
import { doResolveUris } from 'redux/actions/claims'; import { doResolveUris } from 'redux/actions/claims';
import { import {
makeSelectClaimForUri, makeSelectClaimForUri,
makeSelectClaimIsMine, selectClaimIsMineForUri,
selectFetchingMyChannels, selectFetchingMyChannels,
selectMyClaimIdsRaw, selectMyClaimIdsRaw,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
@ -41,7 +41,7 @@ const select = (state, props) => {
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: makeSelectClaimForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
isFetchingComments: selectIsFetchingComments(state), isFetchingComments: selectIsFetchingComments(state),
isFetchingCommentsById: selectIsFetchingCommentsById(state), isFetchingCommentsById: selectIsFetchingCommentsById(state),
isFetchingReacts: selectIsFetchingReacts(state), isFetchingReacts: selectIsFetchingReacts(state),

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { doResolveUris } from 'redux/actions/claims'; import { doResolveUris } from 'redux/actions/claims';
import { makeSelectClaimIsMine, selectMyChannelClaimIds, makeSelectClaimForUri } from 'redux/selectors/claims'; import { selectClaimIsMineForUri, selectMyChannelClaimIds, makeSelectClaimForUri } from 'redux/selectors/claims';
import { selectIsFetchingCommentsByParentId, selectRepliesForParentId } from 'redux/selectors/comments'; import { selectIsFetchingCommentsByParentId, selectRepliesForParentId } from 'redux/selectors/comments';
import { selectUserVerifiedEmail } from 'redux/selectors/user'; import { selectUserVerifiedEmail } from 'redux/selectors/user';
import CommentsReplies from './view'; import CommentsReplies from './view';
@ -15,7 +15,7 @@ const select = (state, props) => {
return { return {
fetchedReplies, fetchedReplies,
resolvedReplies, resolvedReplies,
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
userCanComment: IS_WEB ? Boolean(selectUserVerifiedEmail(state)) : true, userCanComment: IS_WEB ? Boolean(selectUserVerifiedEmail(state)) : true,
myChannelIds: selectMyChannelClaimIds(state), myChannelIds: selectMyChannelClaimIds(state),
isFetchingByParentId: selectIsFetchingCommentsByParentId(state), isFetchingByParentId: selectIsFetchingCommentsByParentId(state),

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
makeSelectClaimIsMine, selectClaimIsMineForUri,
makeSelectClaimForUri, makeSelectClaimForUri,
selectHasChannels, selectHasChannels,
makeSelectClaimIsStreamPlaceholder, makeSelectClaimIsStreamPlaceholder,
@ -19,7 +19,7 @@ import { makeSelectFileRenderModeForUri } from 'redux/selectors/content';
const select = (state, props) => ({ const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
fileInfo: makeSelectFileInfoForUri(props.uri)(state), fileInfo: makeSelectFileInfoForUri(props.uri)(state),
renderMode: makeSelectFileRenderModeForUri(props.uri)(state), renderMode: makeSelectFileRenderModeForUri(props.uri)(state),
costInfo: makeSelectCostInfoForUri(props.uri)(state), costInfo: makeSelectCostInfoForUri(props.uri)(state),

View file

@ -1,9 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import { makeSelectClaimForUri, makeSelectMetadataForUri, selectClaimIsMineForUri } from 'redux/selectors/claims';
makeSelectClaimForUri,
makeSelectMetadataForUri,
makeSelectClaimIsMine,
} 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';
@ -11,7 +7,7 @@ import FileDescription from './view';
const select = (state, props) => ({ const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
metadata: makeSelectMetadataForUri(props.uri)(state), metadata: makeSelectMetadataForUri(props.uri)(state),
user: selectUser(state), user: selectUser(state),
pendingAmount: makeSelectPendingAmountByUri(props.uri)(state), pendingAmount: makeSelectPendingAmountByUri(props.uri)(state),

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimIsMine, makeSelectClaimForUri, makeSelectClaimWasPurchased } from 'redux/selectors/claims'; import { selectClaimIsMineForUri, makeSelectClaimForUri, makeSelectClaimWasPurchased } from 'redux/selectors/claims';
import { import {
makeSelectFileInfoForUri, makeSelectFileInfoForUri,
makeSelectDownloadingForUri, makeSelectDownloadingForUri,
@ -15,7 +15,7 @@ const select = (state, props) => ({
fileInfo: makeSelectFileInfoForUri(props.uri)(state), fileInfo: makeSelectFileInfoForUri(props.uri)(state),
downloading: makeSelectDownloadingForUri(props.uri)(state), downloading: makeSelectDownloadingForUri(props.uri)(state),
loading: makeSelectLoadingForUri(props.uri)(state), loading: makeSelectLoadingForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
costInfo: makeSelectCostInfoForUri(props.uri)(state), costInfo: makeSelectCostInfoForUri(props.uri)(state),
claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state), claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state),

View file

@ -1,11 +1,11 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimForUri, makeSelectClaimWasPurchased, makeSelectClaimIsMine } from 'redux/selectors/claims'; import { makeSelectClaimForUri, makeSelectClaimWasPurchased, selectClaimIsMineForUri } 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), claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state), claimWasPurchased: makeSelectClaimWasPurchased(props.uri)(state),
costInfo: makeSelectCostInfoForUri(props.uri)(state), costInfo: makeSelectCostInfoForUri(props.uri)(state),
fetching: makeSelectFetchingCostInfoForUri(props.uri)(state), fetching: makeSelectFetchingCostInfoForUri(props.uri)(state),

View file

@ -3,7 +3,7 @@ import {
makeSelectClaimForUri, makeSelectClaimForUri,
makeSelectContentTypeForUri, makeSelectContentTypeForUri,
makeSelectMetadataForUri, makeSelectMetadataForUri,
makeSelectClaimIsMine, selectClaimIsMineForUri,
} 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';
@ -19,7 +19,7 @@ const select = (state, props) => ({
metadata: makeSelectMetadataForUri(props.uri)(state), metadata: makeSelectMetadataForUri(props.uri)(state),
user: selectUser(state), user: selectUser(state),
pendingAmount: makeSelectPendingAmountByUri(props.uri)(state), pendingAmount: makeSelectPendingAmountByUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
}); });
const perform = (dispatch) => ({ const perform = (dispatch) => ({

View file

@ -1,11 +1,11 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimForUri, makeSelectClaimIsMine } from 'redux/selectors/claims'; import { makeSelectClaimForUri, selectClaimIsMineForUri } from 'redux/selectors/claims';
import PostViewer from './view'; import PostViewer from './view';
import { doOpenModal } from 'redux/actions/app'; import { doOpenModal } from 'redux/actions/app';
const select = (state, props) => ({ const select = (state, props) => ({
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
}); });
export default connect(select, { export default connect(select, {

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
makeSelectClaimIsMine, selectClaimIsMineForUri,
makeSelectTitleForUri, makeSelectTitleForUri,
makeSelectThumbnailForUri, makeSelectThumbnailForUri,
makeSelectClaimForUri, makeSelectClaimForUri,
@ -18,7 +18,7 @@ const select = (state, props) => {
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: makeSelectClaimIsMine(props.uri)(state), channelIsMine: selectClaimIsMineForUri(state, props.uri),
isResolvingUri: makeSelectIsUriResolving(props.uri)(state), isResolvingUri: makeSelectIsUriResolving(props.uri)(state),
blackListedOutpoints: selectBlackListedOutpoints(state), blackListedOutpoints: selectBlackListedOutpoints(state),
}; };

View file

@ -1,5 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { makeSelectClaimIsMine, makeSelectClaimForUri } from 'redux/selectors/claims'; import { selectClaimIsMineForUri, makeSelectClaimForUri } 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';
@ -13,7 +13,7 @@ const select = (state, props) => {
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: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
}; };
}; };

View file

@ -2,7 +2,7 @@ import { connect } from 'react-redux';
import { import {
makeSelectTitleForUri, makeSelectTitleForUri,
makeSelectClaimForUri, makeSelectClaimForUri,
makeSelectClaimIsMine, selectClaimIsMineForUri,
selectFetchingMyChannels, selectFetchingMyChannels,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { doHideModal } from 'redux/actions/app'; import { doHideModal } from 'redux/actions/app';
@ -18,7 +18,7 @@ const select = (state, props) => ({
activeChannelClaim: selectActiveChannelClaim(state), activeChannelClaim: selectActiveChannelClaim(state),
balance: selectBalance(state), balance: selectBalance(state),
claim: makeSelectClaimForUri(props.uri, false)(state), claim: makeSelectClaimForUri(props.uri, false)(state),
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
fetchingChannels: selectFetchingMyChannels(state), fetchingChannels: selectFetchingMyChannels(state),
incognito: selectIncognito(state), incognito: selectIncognito(state),
instantTipEnabled: makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state), instantTipEnabled: makeSelectClientSetting(SETTINGS.INSTANT_PURCHASE_ENABLED)(state),

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
makeSelectClaimIsMine, selectClaimIsMineForUri,
makeSelectIsAbandoningClaimForUri, makeSelectIsAbandoningClaimForUri,
makeSelectClaimForClaimId, makeSelectClaimForClaimId,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
@ -15,7 +15,7 @@ const select = (state, props) => {
return { return {
claim, claim,
uri, uri,
claimIsMine: makeSelectClaimIsMine(uri)(state), claimIsMine: selectClaimIsMineForUri(state, uri),
isAbandoning: makeSelectIsAbandoningClaimForUri(uri)(state), isAbandoning: makeSelectIsAbandoningClaimForUri(uri)(state),
collectionName: makeSelectNameForCollectionId(props.collectionId)(state), collectionName: makeSelectNameForCollectionId(props.collectionId)(state),
}; };

View file

@ -4,14 +4,14 @@ import {
makeSelectTitleForUri, makeSelectTitleForUri,
makeSelectClaimForUri, makeSelectClaimForUri,
makeSelectIsAbandoningClaimForUri, makeSelectIsAbandoningClaimForUri,
makeSelectClaimIsMine, selectClaimIsMineForUri,
} from 'redux/selectors/claims'; } from 'redux/selectors/claims';
import { doResolveUri } from 'redux/actions/claims'; import { doResolveUri } from 'redux/actions/claims';
import { doHideModal } from 'redux/actions/app'; import { doHideModal } from 'redux/actions/app';
import ModalRemoveFile from './view'; import ModalRemoveFile from './view';
const select = (state, props) => ({ const select = (state, props) => ({
claimIsMine: makeSelectClaimIsMine(props.uri)(state), claimIsMine: selectClaimIsMineForUri(state, props.uri),
title: makeSelectTitleForUri(props.uri)(state), title: makeSelectTitleForUri(props.uri)(state),
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
isAbandoning: makeSelectIsAbandoningClaimForUri(props.uri)(state), isAbandoning: makeSelectIsAbandoningClaimForUri(props.uri)(state),

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { import {
makeSelectClaimIsMine, selectClaimIsMineForUri,
makeSelectTitleForUri, makeSelectTitleForUri,
makeSelectThumbnailForUri, makeSelectThumbnailForUri,
makeSelectCoverForUri, makeSelectCoverForUri,
@ -21,7 +21,7 @@ const select = (state, props) => ({
title: makeSelectTitleForUri(props.uri)(state), title: makeSelectTitleForUri(props.uri)(state),
thumbnail: makeSelectThumbnailForUri(props.uri)(state), thumbnail: makeSelectThumbnailForUri(props.uri)(state),
cover: makeSelectCoverForUri(props.uri)(state), cover: makeSelectCoverForUri(props.uri)(state),
channelIsMine: makeSelectClaimIsMine(props.uri)(state), channelIsMine: selectClaimIsMineForUri(state, props.uri),
page: selectCurrentChannelPage(state), page: selectCurrentChannelPage(state),
claim: makeSelectClaimForUri(props.uri)(state), claim: makeSelectClaimForUri(props.uri)(state),
isSubscribed: makeSelectIsSubscribed(props.uri, true)(state), isSubscribed: makeSelectIsSubscribed(props.uri, true)(state),

View file

@ -5,7 +5,7 @@ import CollectionPage from './view';
import { import {
makeSelectTitleForUri, makeSelectTitleForUri,
makeSelectThumbnailForUri, makeSelectThumbnailForUri,
makeSelectClaimIsMine, selectClaimIsMineForUri,
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: makeSelectClaimIsMine(uri)(state), // or collection is mine? isMyClaim: selectClaimIsMineForUri(state, uri), // 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,
makeSelectClaimIsMine, selectClaimIsMineForUri,
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: makeSelectClaimIsMine(uri)(state), claimIsMine: selectClaimIsMineForUri(state, uri),
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, makeSelectClaimIsMine, selectMyChannelClaims } from 'redux/selectors/claims'; import { makeSelectClaimForUri, 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';
@ -470,7 +470,7 @@ 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 { txid, nout, claim_id: claimId } = makeSelectClaimForUri(uri)(state);
const claimIsMine = makeSelectClaimIsMine(uri)(state); const claimIsMine = selectClaimIsMineForUri(state, uri);
const outpoint = `${txid}:${nout}`; const outpoint = `${txid}:${nout}`;
if (claimIsMine) { if (claimIsMine) {

View file

@ -5,7 +5,7 @@ import * as MODALS from 'constants/modal_types';
import { ipcRenderer } from 'electron'; import { ipcRenderer } from 'electron';
// @endif // @endif
import { doOpenModal } from 'redux/actions/app'; import { doOpenModal } from 'redux/actions/app';
import { makeSelectClaimForUri, makeSelectClaimIsMine, makeSelectClaimWasPurchased } from 'redux/selectors/claims'; import { makeSelectClaimForUri, selectClaimIsMineForUri, makeSelectClaimWasPurchased } from 'redux/selectors/claims';
import { import {
makeSelectFileInfoForUri, makeSelectFileInfoForUri,
selectFileInfosByOutpoint, selectFileInfosByOutpoint,
@ -151,7 +151,7 @@ export function doPlayUri(
) { ) {
return (dispatch: Dispatch, getState: () => any) => { return (dispatch: Dispatch, getState: () => any) => {
const state = getState(); const state = getState();
const isMine = makeSelectClaimIsMine(uri)(state); const isMine = selectClaimIsMineForUri(state, uri);
const fileInfo = makeSelectFileInfoForUri(uri)(state); const fileInfo = makeSelectFileInfoForUri(uri)(state);
const uriIsStreamable = makeSelectUriIsStreamable(uri)(state); const uriIsStreamable = makeSelectUriIsStreamable(uri)(state);
const downloadingByOutpoint = selectDownloadingByOutpoint(state); const downloadingByOutpoint = selectDownloadingByOutpoint(state);

View file

@ -199,6 +199,44 @@ export const selectMyActiveClaims = createSelector(
} }
); );
// Helper for 'selectClaimIsMineForUri'.
// Returns undefined string if unable to normalize or is not valid.
const selectNormalizedAndVerifiedUri = createCachedSelector(
(state, rawUri) => rawUri,
(rawUri) => {
try {
const uri = normalizeURI(rawUri);
if (isURIValid(uri, false)) {
return uri;
}
} catch (e) {}
return undefined;
}
)((state, rawUri) => String(rawUri));
export const selectClaimIsMineForUri = (state: State, rawUri: string) => {
// Not memoizing this selector because:
// (1) The workload is somewhat lightweight.
// (2) Since it depends on 'selectClaimsByUri', memoization won't work anyway
// because the array is constantly invalidated.
const uri = selectNormalizedAndVerifiedUri(state, rawUri);
if (!uri) {
return false;
}
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)))
);
};
// DEPRECATED - use selectClaimIsMineForUri instead.
export const makeSelectClaimIsMine = (rawUri: string) => { export const makeSelectClaimIsMine = (rawUri: string) => {
let uri; let uri;
try { try {