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

Merged
6ea86b96 merged 1 commit from fetch-claim-list-mine into master 2017-05-29 22:17:39 +02:00
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
}) })
kauffj commented 2017-05-28 17:40:02 +02:00 (Migrated from github.com)
Review

I suspect this will cause misses, since they are not typically built with claimSequence and claimId.

I suspect this will cause misses, since they are not typically built with claimSequence and claimId.
6ea86b96 commented 2017-05-29 11:21:38 +02:00 (Migrated from github.com)
Review

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.

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.
kauffj commented 2017-05-29 22:13:32 +02:00 (Migrated from github.com)
Review

We were saying the same thing here.

We were saying the same thing here.
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
}) })
6ea86b96 commented 2017-05-29 11:34:06 +02:00 (Migrated from github.com)
Review

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, { 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
} }
) )