Store claims by claim_id and fileinfo by sd_hash #192

Merged
6ea86b96 merged 5 commits from claims-by-id into master 2017-06-07 17:09:39 +02:00
7 changed files with 80 additions and 53 deletions

1
.gitignore vendored
View file

@ -16,3 +16,4 @@ dist
.#* .#*
build/daemon.zip build/daemon.zip
.vimrc

View file

@ -10,23 +10,9 @@ export function doFetchCostInfoForUri(uri) {
return function(dispatch, getState) { return function(dispatch, getState) {
const state = getState(), const state = getState(),
claim = selectClaimsByUri(state)[uri], claim = selectClaimsByUri(state)[uri],
isResolving = selectResolvingUris(state).indexOf(uri) !== -1,
isGenerous = selectSettingsIsGenerous(state); isGenerous = selectSettingsIsGenerous(state);
if (claim === null) { if (!claim) return null
//claim doesn't exist, nothing to fetch a cost for
return;
}
if (!claim) {
setTimeout(() => {
dispatch(doFetchCostInfoForUri(uri));
}, 1000);
if (!isResolving) {
dispatch(doResolveUri(uri));
}
return;
}
function begin() { function begin() {
dispatch({ dispatch({

View file

@ -4,16 +4,21 @@ import { doFetchCostInfoForUri } from "actions/cost_info";
import { import {
makeSelectCostInfoForUri, makeSelectCostInfoForUri,
makeSelectFetchingCostInfoForUri, makeSelectFetchingCostInfoForUri,
} from "selectors/cost_info"; } from 'selectors/cost_info'
import FilePrice from "./view"; import {
makeSelectClaimForUri,
} from 'selectors/claims'
import FilePrice from './view'
const makeSelect = () => { const makeSelect = () => {
const selectCostInfoForUri = makeSelectCostInfoForUri(); const selectCostInfoForUri = makeSelectCostInfoForUri();
const selectFetchingCostInfoForUri = makeSelectFetchingCostInfoForUri(); const selectFetchingCostInfoForUri = makeSelectFetchingCostInfoForUri();
const selectClaim = makeSelectClaimForUri();
const select = (state, props) => ({ const select = (state, props) => ({
costInfo: selectCostInfoForUri(state, props), costInfo: selectCostInfoForUri(state, props),
fetching: selectFetchingCostInfoForUri(state, props), fetching: selectFetchingCostInfoForUri(state, props),
claim: selectClaim(state, props),
}); });
return select; return select;

View file

@ -11,9 +11,15 @@ class FilePrice extends React.Component {
} }
fetchCost(props) { fetchCost(props) {
const { costInfo, fetchCostInfo, uri, fetching } = props; const {
costInfo,
fetchCostInfo,
uri,
fetching,
claim,
} = props;
if (costInfo === undefined && !fetching) { if (costInfo === undefined && !fetching && claim) {
fetchCostInfo(uri); fetchCostInfo(uri);
} }
} }

View file

@ -19,11 +19,15 @@ class FileTile extends React.Component {
} }
componentDidMount() { componentDidMount() {
const { isResolvingUri, resolveUri, claim, uri } = this.props; this.resolve(this.props);
}
if (!isResolvingUri && !claim && uri) { componentWillReceiveProps(nextProps) {
resolveUri(uri); this.resolve(nextProps);
} }
resolve({ isResolvingUri, claim, uri, resolveUri }) {
if (!isResolvingUri && claim === undefined && uri) resolveUri(uri);
} }
handleMouseOver() { handleMouseOver() {

View file

@ -7,23 +7,24 @@ const defaultState = {};
reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) { reducers[types.RESOLVE_URI_COMPLETED] = function(state, action) {
const { uri, certificate, claim } = action.data; const { uri, certificate, claim } = action.data;
const newClaims = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
const byId = Object.assign({}, state.byId);
newClaims[uri] = claim; if (claim) {
byId[claim.claim_id] = claim;
//This needs a sanity boost... byUri[uri] = claim.claim_id;
if (certificate !== undefined && claim === undefined) { } else if (claim === undefined && certificate !== undefined) {
const uriParts = lbryuri.parse(uri); byId[certificate.claim_id] = certificate;
// newChannelClaims[uri] = certificate byUri[uri] = certificate.claim_id;
if (claim === undefined) { } else {
newClaims[uri] = certificate; byUri[uri] = null;
}
} }
return Object.assign({}, state, { return Object.assign({}, state, {
claimsByUri: newClaims, byId,
claimsByUri: byUri
}); });
}; }
reducers[types.RESOLVE_URI_CANCELED] = function(state, action) { reducers[types.RESOLVE_URI_CANCELED] = function(state, action) {
const uri = action.data.uri; const uri = action.data.uri;
@ -41,26 +42,24 @@ reducers[types.FETCH_CLAIM_LIST_MINE_STARTED] = function(state, action) {
}; };
reducers[types.FETCH_CLAIM_LIST_MINE_COMPLETED] = function(state, action) { reducers[types.FETCH_CLAIM_LIST_MINE_COMPLETED] = function(state, action) {
const { claims } = action.data; const {
claims,
} = action.data;
const myClaims = new Set(state.myClaims); const myClaims = new Set(state.myClaims);
const byUri = Object.assign({}, state.claimsByUri); const byUri = Object.assign({}, state.claimsByUri);
const byId = Object.assign({}, state.byId);
claims.forEach(claim => { claims.forEach(claim => {
const uri = lbryuri.build({ myClaims.add(claim.claim_id);
contentName: claim.name, byId[claim.claim_id] = claim;
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, byId,
}); });
}; }
// reducers[types.FETCH_CHANNEL_CLAIMS_STARTED] = function(state, action) { // reducers[types.FETCH_CHANNEL_CLAIMS_STARTED] = function(state, action) {
// const { // const {

View file

@ -1,12 +1,38 @@
import { createSelector } from "reselect"; import { createSelector } from "reselect";
import lbryuri from "lbryuri"; import lbryuri from "lbryuri";
export const _selectState = state => state.claims || {}; const _selectState = state => state.claims || {};
export const selectClaimsById = createSelector(
_selectState,
(state) => state.byId || {}
);
export const selectClaimsByUri = createSelector( export const selectClaimsByUri = createSelector(
_selectState, _selectState,
state => state.claimsByUri || {} selectClaimsById,
); (state, byId) => {
const byUri = state.claimsByUri || {};
const claims = {};
Object.keys(byUri).forEach(uri => {
const claimId = byUri[uri];
// NOTE returning a null claim allows us to differentiate between an
// undefined (never fetched claim) and one which just doesn't exist. Not
// the cleanest solution but couldn't think of anything better right now
if (claimId === null) {
claims[uri] = null;
} else {
const claim = byId[claimId];
claims[uri] = claim;
}
})
return claims;
}
)
export const selectAllClaimsByChannel = createSelector( export const selectAllClaimsByChannel = createSelector(
_selectState, _selectState,
@ -74,14 +100,14 @@ export const selectMyClaims = createSelector(
export const selectMyClaimsOutpoints = createSelector( export const selectMyClaimsOutpoints = createSelector(
selectMyClaims, selectMyClaims,
selectClaimsByUri, selectClaimsById,
(claimIds, byUri) => { (claimIds, byId) => {
const outpoints = []; const outpoints = [];
claimIds.forEach(claimId => { claimIds.forEach(claimId => {
const claim = byUri[claimId]; const claim = byId[claimId];
if (claim) outpoints.push(`${claim.txid}:${claim.nout}`); if (claim) outpoints.push(`${claim.txid}:${claim.nout}`);
}); })
return outpoints; return outpoints;
} }