Skip to content

Commit

Permalink
Merge pull request #166 from steemit/optimization
Browse files Browse the repository at this point in the history
optimization: don't parse json data twice
  • Loading branch information
Fabien authored Jun 17, 2017
2 parents af9714e + 90a8186 commit 02354c5
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ class Steem extends EventEmitter {

const releaseMessage = this.listenTo(this.ws, 'message', (message) => {
debugWs('Received message', message.data);
const id = JSON.parse(message.data).id;
const data = JSON.parse(message.data);
const id = data.id;
const msToRespond = Date.now() - this.requestsTime[id];
delete this.requestsTime[id];
if (msToRespond > expectedResponseMs) {
debugWs(`Message received in ${msToRespond}ms, it's over the expected response time of ${expectedResponseMs}ms`, message.data);
}
this.emit('message', JSON.parse(message.data));
this.emit('message', data);
});

this.releases = this.releases.concat([
Expand Down Expand Up @@ -226,7 +227,7 @@ class Steem extends EventEmitter {
return;
}

this.inFlight -= 1;
// this.inFlight -= 1;
release();

// Our message's response came back
Expand Down Expand Up @@ -257,7 +258,7 @@ class Steem extends EventEmitter {
debugWs('Sending message', payload);
this.requestsTime[id] = Date.now();

this.inFlight += 1;
// this.inFlight += 1;
this.ws.send(payload);
}))
.nodeify(callback);
Expand Down

0 comments on commit 02354c5

Please sign in to comment.