From a6709ffc266c9d39c5098d42e412a7582fb83c24 Mon Sep 17 00:00:00 2001 From: 6ea86b96 <6ea86b96@gmail.com> Date: Sun, 28 May 2017 17:01:11 +0400 Subject: [PATCH] Try to only keep one copy of each claim in the store --- ui/js/actions/content.js | 6 +++--- ui/js/actions/file_info.js | 4 ++-- ui/js/constants/action_types.js | 4 ++-- ui/js/reducers/claims.js | 25 +++++++++++++++++++------ ui/js/reducers/file_info.js | 4 +++- ui/js/selectors/claims.js | 19 +++++++++++-------- 6 files changed, 40 insertions(+), 22 deletions(-) diff --git a/ui/js/actions/content.js b/ui/js/actions/content.js index e09bd5ea1..a52634bca 100644 --- a/ui/js/actions/content.js +++ b/ui/js/actions/content.js @@ -274,16 +274,16 @@ export function doFetchClaimsByChannel(uri) { } } -export function doClaimListMine() { +export function doFetchClaimListMine() { return function(dispatch, getState) { dispatch({ - type: types.CLAIM_LIST_MINE_STARTED + type: types.FETCH_CLAIM_LIST_MINE_STARTED }) lbry.claim_list_mine().then((claims) => { dispatch({ - type: types.CLAIM_LIST_MINE_COMPLETED, + type: types.FETCH_CLAIM_LIST_MINE_COMPLETED, data: { claims } diff --git a/ui/js/actions/file_info.js b/ui/js/actions/file_info.js index 23ba50e71..44d76885c 100644 --- a/ui/js/actions/file_info.js +++ b/ui/js/actions/file_info.js @@ -1,7 +1,7 @@ import * as types from 'constants/action_types' import lbry from 'lbry' import { - doClaimListMine + doFetchClaimListMine } from 'actions/content' import { selectClaimsByUri, @@ -110,7 +110,7 @@ export function doFetchFileInfosAndPublishedClaims() { isFileInfoListPending = selectFileListIsPending(state) if (isClaimListMinePending === undefined) { - dispatch(doClaimListMine()) + dispatch(doFetchClaimListMine()) } if (isFileInfoListPending === undefined) { diff --git a/ui/js/constants/action_types.js b/ui/js/constants/action_types.js index 1d1dab869..9f70de9b9 100644 --- a/ui/js/constants/action_types.js +++ b/ui/js/constants/action_types.js @@ -40,8 +40,8 @@ export const RESOLVE_URI_COMPLETED = 'RESOLVE_URI_COMPLETED' export const RESOLVE_URI_CANCELED = 'RESOLVE_URI_CANCELED' export const FETCH_CHANNEL_CLAIMS_STARTED = 'FETCH_CHANNEL_CLAIMS_STARTED' export const FETCH_CHANNEL_CLAIMS_COMPLETED = 'FETCH_CHANNEL_CLAIMS_COMPLETED' -export const CLAIM_LIST_MINE_STARTED = 'CLAIM_LIST_MINE_STARTED' -export const CLAIM_LIST_MINE_COMPLETED = 'CLAIM_LIST_MINE_COMPLETED' +export const FETCH_CLAIM_LIST_MINE_STARTED = 'FETCH_CLAIM_LIST_MINE_STARTED' +export const FETCH_CLAIM_LIST_MINE_COMPLETED = 'FETCH_CLAIM_LIST_MINE_COMPLETED' export const FILE_LIST_STARTED = 'FILE_LIST_STARTED' export const FILE_LIST_COMPLETED = 'FILE_LIST_COMPLETED' export const FETCH_FILE_INFO_STARTED = 'FETCH_FILE_INFO_STARTED' diff --git a/ui/js/reducers/claims.js b/ui/js/reducers/claims.js index 7105a0d33..b75b00a4d 100644 --- a/ui/js/reducers/claims.js +++ b/ui/js/reducers/claims.js @@ -40,20 +40,33 @@ reducers[types.RESOLVE_URI_CANCELED] = function(state, action) { } -reducers[types.CLAIM_LIST_MINE_STARTED] = function(state, action) { +reducers[types.FETCH_CLAIM_LIST_MINE_STARTED] = function(state, action) { return Object.assign({}, state, { isClaimListMinePending: true }) } -reducers[types.CLAIM_LIST_MINE_COMPLETED] = function(state, action) { - const myClaims = Object.assign({}, state.myClaims) - action.data.claims.forEach((claim) => { - myClaims[claim.claim_id] = claim +reducers[types.FETCH_CLAIM_LIST_MINE_COMPLETED] = function(state, action) { + const { + claims, + } = action.data + const myClaims = new Set(state.myClaims) + const byUri = Object.assign({}, state.claimsByUri) + + claims.forEach(claim => { + const uri = lbryuri.build({ + contentName: claim.name, + claimId: claim.claim_id, + claimSequence: claim.nout, + }) + myClaims.add(uri) + byUri[uri] = claim }) + return Object.assign({}, state, { isClaimListMinePending: false, - myClaims: myClaims + myClaims: myClaims, + claimsByUri: byUri, }) } diff --git a/ui/js/reducers/file_info.js b/ui/js/reducers/file_info.js index 811c829ef..0b06e591b 100644 --- a/ui/js/reducers/file_info.js +++ b/ui/js/reducers/file_info.js @@ -18,7 +18,9 @@ reducers[types.FILE_LIST_COMPLETED] = function(state, action) { const newFileInfos = Object.assign({}, state.fileInfos) fileInfos.forEach((fileInfo) => { - newFileInfos[fileInfo.outpoint] = fileInfo + const { outpoint } = fileInfo + + if (outpoint) newFileInfos[fileInfo.outpoint] = fileInfo }) return Object.assign({}, state, { diff --git a/ui/js/selectors/claims.js b/ui/js/selectors/claims.js index 9a76b872e..5b9b9d0b5 100644 --- a/ui/js/selectors/claims.js +++ b/ui/js/selectors/claims.js @@ -42,7 +42,8 @@ const selectMetadataForUri = (state, props) => { const claim = selectClaimForUri(state, props) const metadata = claim && claim.value && claim.value.stream && claim.value.stream.metadata - return metadata ? metadata : (claim === undefined ? undefined : null) + const value = metadata ? metadata : (claim === undefined ? undefined : null) + return value } export const makeSelectMetadataForUri = () => { @@ -80,18 +81,20 @@ export const selectClaimListMineIsPending = createSelector( export const selectMyClaims = createSelector( _selectState, - (state) => state.myClaims || {} + (state) => state.myClaims || new Set() ) export const selectMyClaimsOutpoints = createSelector( selectMyClaims, - (claims) => { - if (!claims) { - return [] - } + selectClaimsByUri, + (claimIds, byUri) => { + const outpoints = [] - return Object.values(claims).map((claim) => { - return `${claim.txid}:${claim.nout}` + claimIds.forEach(claimId => { + const claim = byUri[claimId] + if (claim) outpoints.push(`${claim.txid}:${claim.nout}`) }) + + return outpoints } )