Try to only keep one copy of each claim in the store #149
6 changed files with 40 additions and 22 deletions
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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'
|
||||
|
|
|
@ -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
|
||||
})
|
||||
|
||||
I think rather than misses, this is going to cause duplicates. So rather than having dupes separated into I think long term it might be better to store claims in I think rather than misses, this is going to cause duplicates. So rather than having dupes separated into `claimsByUri` and `myClaims` now we've just moved the duplication problem into the `claimsByUri` object, but a step in the right direction perhaps for removing dupes?
I think long term it might be better to store claims in `claims.byId` and then map `byUri`, `myClaims`, etc, to claim ids.
We were saying the same thing here. We were saying the same thing here.
|
||||
return Object.assign({}, state, {
|
||||
isClaimListMinePending: false,
|
||||
myClaims: myClaims
|
||||
myClaims: myClaims,
|
||||
claimsByUri: byUri,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
})
|
||||
I have a file with no outpoint locally. It's one that I tried to upload but it didn't work for some reason. I have a file with no outpoint locally. It's one that I tried to upload but it didn't work for some reason.
|
||||
|
||||
return Object.assign({}, state, {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue
I suspect this will cause misses, since they are not typically built with claimSequence and claimId.