Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
fix: avoid startup delay updating node count in large clusters
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Apr 29, 2019
1 parent eaaceac commit 65a50cd
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,29 +235,32 @@ class App extends Component {
try {
const oldNodes = this.state.nodes;
const newNodes = await this.connection.getClusterNodes();
const nodes = [];

let modified = oldNodes.length !== newNodes.length;

const maybeSetState = () => {
if (modified) {
this.setState({nodes});
modified = false;
}
};
for (const newNode of newNodes) {
const oldNode = oldNodes.find(node => node.id === newNode.id);
if (oldNode) {
newNode.lat = oldNode.lat;
newNode.lng = oldNode.lng;
newNode.terminated = oldNode.terminated;
nodes.push(oldNode);
} else {
const ip = newNode.gossip.split(':')[0];
const [lat, lng] = await geoip(ip);
newNode.lat = lat;
newNode.lng = lng;
nodes.push(newNode);
modified = true;
}
maybeSetState();
}

if (modified) {
console.log('newNodes', newNodes);
this.setState({nodes: newNodes});
}
maybeSetState();
} catch (err) {
this.setState({nodes: []});
console.log('getClusterNodes failed:', err.message);
}

Expand Down

0 comments on commit 65a50cd

Please sign in to comment.