interface: graph reducer fix receive before pending bug

This commit is contained in:
Logan Allen 2021-03-09 14:28:10 -06:00
parent 4e9873359d
commit 731732a86e
3 changed files with 33 additions and 8 deletions

View File

@ -58,12 +58,16 @@ const addGraph = (json, state) => {
let resource = data.resource.ship + '/' + data.resource.name; let resource = data.resource.ship + '/' + data.resource.name;
state.graphs[resource] = new BigIntOrderedMap(); state.graphs[resource] = new BigIntOrderedMap();
state.graphHashmap[resource] = {};
for (let idx in data.graph) { for (let idx in data.graph) {
let item = data.graph[idx]; let item = data.graph[idx];
let index = bigInt(idx); let index = bigInt(idx);
let node = _processNode(item); let node = _processNode(item);
if (node.post.hash) {
state.graphHashmap[resource][node.post.hash] = true;
}
state.graphs[resource].set( state.graphs[resource].set(
index, index,
@ -140,7 +144,11 @@ const addNodes = (json, state) => {
}; };
const _removePending = (graph, post) => { const _removePending = (graph, post) => {
if (post.hash && state.pendingIndices[post.hash]) { if (!post.hash) {
return graph;
}
if (state.pendingIndices[post.hash]) {
let index = state.pendingIndices[post.hash]; let index = state.pendingIndices[post.hash];
if (index.split('/').length === 0) { return; } if (index.split('/').length === 0) { return; }
@ -151,7 +159,7 @@ const addNodes = (json, state) => {
graph = _remove(graph, indexArr); graph = _remove(graph, indexArr);
delete state.pendingIndices[post.hash]; delete state.pendingIndices[post.hash];
} }
return graph; return graph;
}; };
@ -163,6 +171,11 @@ const addNodes = (json, state) => {
if (!(resource in state.graphs)) { if (!(resource in state.graphs)) {
state.graphs[resource] = new BigIntOrderedMap(); state.graphs[resource] = new BigIntOrderedMap();
} }
if (!(resource in state.graphHashmap)) {
state.graphHashmap[resource] = {};
}
state.graphKeys.add(resource); state.graphKeys.add(resource);
let indices = Array.from(Object.keys(data.nodes)); let indices = Array.from(Object.keys(data.nodes));
@ -178,21 +191,32 @@ const addNodes = (json, state) => {
indices.forEach((index) => { indices.forEach((index) => {
let node = data.nodes[index]; let node = data.nodes[index];
graph = _removePending(graph, node.post); graph = _removePending(graph, node.post);
if (index.split('/').length === 0) { return; } if (index.split('/').length === 0) { return; }
index = index.split('/').slice(1).map((ind) => { let indexArr = index.split('/').slice(1).map((ind) => {
return bigInt(ind); return bigInt(ind);
}); });
if (index.length === 0) { return; } if (indexArr.length === 0) { return; }
if (node.post.hash) {
if (node.post.pending &&
node.post.hash in state.graphHashmap[resource]) {
return;
}
state.graphHashmap[resource][node.post.hash] = true;
}
node.children = mapifyChildren(node?.children || {}); node.children = mapifyChildren(node?.children || {});
graph = _addNode( graph = _addNode(
graph, graph,
index, indexArr,
node node
); );
}); });
state.graphs[resource] = graph; state.graphs[resource] = graph;

View File

@ -100,7 +100,8 @@ export default class GlobalStore extends BaseStore<StoreState> {
notificationsCount: 0, notificationsCount: 0,
settings: {}, settings: {},
pendingJoin: {}, pendingJoin: {},
pendingIndices: {} pendingIndices: {},
graphHashmap: {}
}; };
} }

View File

@ -79,7 +79,7 @@ export function LinkResource(props: LinkResourceProps) {
baseUrl={resourceUrl} baseUrl={resourceUrl}
group={group} group={group}
path={resource.group} path={resource.group}
pendingSize={Object.keys(props.pendingIndices || {}).length} pendingSize={Object.keys(pendingIndices || {}).length}
api={api} api={api}
mb={3} mb={3}
/> />