Try to only keep one copy of each claim in the store

This commit is contained in:
6ea86b96 2017-05-28 17:01:11 +04:00
parent 64c5f10bc1
commit a6709ffc26
6 changed files with 40 additions and 22 deletions

View file

@ -274,16 +274,16 @@ export function doFetchClaimsByChannel(uri) {
} }
} }
export function doClaimListMine() { export function doFetchClaimListMine() {
return function(dispatch, getState) { return function(dispatch, getState) {
dispatch({ dispatch({
type: types.CLAIM_LIST_MINE_STARTED type: types.FETCH_CLAIM_LIST_MINE_STARTED
}) })
lbry.claim_list_mine().then((claims) => { lbry.claim_list_mine().then((claims) => {
dispatch({ dispatch({
type: types.CLAIM_LIST_MINE_COMPLETED, type: types.FETCH_CLAIM_LIST_MINE_COMPLETED,
data: { data: {
claims claims
} }

View file

@ -1,7 +1,7 @@
import * as types from 'constants/action_types' import * as types from 'constants/action_types'
import lbry from 'lbry' import lbry from 'lbry'
import { import {
doClaimListMine doFetchClaimListMine
} from 'actions/content' } from 'actions/content'
import { import {
selectClaimsByUri, selectClaimsByUri,
@ -110,7 +110,7 @@ export function doFetchFileInfosAndPublishedClaims() {
isFileInfoListPending = selectFileListIsPending(state) isFileInfoListPending = selectFileListIsPending(state)
if (isClaimListMinePending === undefined) { if (isClaimListMinePending === undefined) {
dispatch(doClaimListMine()) dispatch(doFetchClaimListMine())
} }
if (isFileInfoListPending === undefined) { if (isFileInfoListPending === undefined) {

View file

@ -40,8 +40,8 @@ export const RESOLVE_URI_COMPLETED = 'RESOLVE_URI_COMPLETED'
export const RESOLVE_URI_CANCELED = 'RESOLVE_URI_CANCELED' export const RESOLVE_URI_CANCELED = 'RESOLVE_URI_CANCELED'
export const FETCH_CHANNEL_CLAIMS_STARTED = 'FETCH_CHANNEL_CLAIMS_STARTED' export const FETCH_CHANNEL_CLAIMS_STARTED = 'FETCH_CHANNEL_CLAIMS_STARTED'
export const FETCH_CHANNEL_CLAIMS_COMPLETED = 'FETCH_CHANNEL_CLAIMS_COMPLETED' export const FETCH_CHANNEL_CLAIMS_COMPLETED = 'FETCH_CHANNEL_CLAIMS_COMPLETED'
export const CLAIM_LIST_MINE_STARTED = 'CLAIM_LIST_MINE_STARTED' export const FETCH_CLAIM_LIST_MINE_STARTED = 'FETCH_CLAIM_LIST_MINE_STARTED'
export const CLAIM_LIST_MINE_COMPLETED = 'CLAIM_LIST_MINE_COMPLETED' export const FETCH_CLAIM_LIST_MINE_COMPLETED = 'FETCH_CLAIM_LIST_MINE_COMPLETED'
export const FILE_LIST_STARTED = 'FILE_LIST_STARTED' export const FILE_LIST_STARTED = 'FILE_LIST_STARTED'
export const FILE_LIST_COMPLETED = 'FILE_LIST_COMPLETED' export const FILE_LIST_COMPLETED = 'FILE_LIST_COMPLETED'
export const FETCH_FILE_INFO_STARTED = 'FETCH_FILE_INFO_STARTED' export const FETCH_FILE_INFO_STARTED = 'FETCH_FILE_INFO_STARTED'

View file

@ -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, { return Object.assign({}, state, {
isClaimListMinePending: true isClaimListMinePending: true
}) })
} }
reducers[types.CLAIM_LIST_MINE_COMPLETED] = function(state, action) { reducers[types.FETCH_CLAIM_LIST_MINE_COMPLETED] = function(state, action) {
const myClaims = Object.assign({}, state.myClaims) const {
action.data.claims.forEach((claim) => { claims,
myClaims[claim.claim_id] = claim } = 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, { return Object.assign({}, state, {
isClaimListMinePending: false, isClaimListMinePending: false,
myClaims: myClaims myClaims: myClaims,
claimsByUri: byUri,
}) })
} }

View file

@ -18,7 +18,9 @@ reducers[types.FILE_LIST_COMPLETED] = function(state, action) {
const newFileInfos = Object.assign({}, state.fileInfos) const newFileInfos = Object.assign({}, state.fileInfos)
fileInfos.forEach((fileInfo) => { fileInfos.forEach((fileInfo) => {
newFileInfos[fileInfo.outpoint] = fileInfo const { outpoint } = fileInfo
if (outpoint) newFileInfos[fileInfo.outpoint] = fileInfo
}) })
return Object.assign({}, state, { return Object.assign({}, state, {

View file

@ -42,7 +42,8 @@ const selectMetadataForUri = (state, props) => {
const claim = selectClaimForUri(state, props) const claim = selectClaimForUri(state, props)
const metadata = claim && claim.value && claim.value.stream && claim.value.stream.metadata 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 = () => { export const makeSelectMetadataForUri = () => {
@ -80,18 +81,20 @@ export const selectClaimListMineIsPending = createSelector(
export const selectMyClaims = createSelector( export const selectMyClaims = createSelector(
_selectState, _selectState,
(state) => state.myClaims || {} (state) => state.myClaims || new Set()
) )
export const selectMyClaimsOutpoints = createSelector( export const selectMyClaimsOutpoints = createSelector(
selectMyClaims, selectMyClaims,
(claims) => { selectClaimsByUri,
if (!claims) { (claimIds, byUri) => {
return [] const outpoints = []
}
return Object.values(claims).map((claim) => { claimIds.forEach(claimId => {
return `${claim.txid}:${claim.nout}` const claim = byUri[claimId]
if (claim) outpoints.push(`${claim.txid}:${claim.nout}`)
}) })
return outpoints
} }
) )