From d15303423210ff2f0fdd54d2573085908d7cc32a Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 1 Feb 2019 22:15:22 +0000 Subject: [PATCH] slow down status updates from mysql to better handle fast updates to close #515 --- storage/mysql/68-mysql.js | 14 +++++++++++--- storage/mysql/package.json | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/storage/mysql/68-mysql.js b/storage/mysql/68-mysql.js index a3362fa5..153c9389 100644 --- a/storage/mysql/68-mysql.js +++ b/storage/mysql/68-mysql.js @@ -106,6 +106,8 @@ module.exports = function(RED) { if (this.mydbConfig) { this.mydbConfig.connect(); var node = this; + var busy = false; + var status = {}; node.mydbConfig.on("state", function(info) { if (info === "connecting") { node.status({fill:"grey",shape:"ring",text:info}); } else if (info === "connected") { node.status({fill:"green",shape:"dot",text:info}); } @@ -124,12 +126,12 @@ module.exports = function(RED) { node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) { if (err) { node.error(err,msg); - node.status({fill:"red",shape:"ring",text:"Error"}); + status = {fill:"red",shape:"ring",text:"Error"}; } else { msg.payload = rows; node.send(msg); - node.status({fill:"green",shape:"dot",text:"OK"}); + status = {fill:"green",shape:"dot",text:"OK"}; } }); } @@ -139,11 +141,17 @@ module.exports = function(RED) { } else { node.error("Database not connected",msg); - node.status({fill:"red",shape:"ring",text:"not yet connected"}); + status = {fill:"red",shape:"ring",text:"not yet connected"}; + } + if (!busy) { + busy = true; + node.status(status); + node.tout = setTimeout(function() { busy = false; node.status(status); },500); } }); node.on('close', function () { + if (node.tout) { clearTimeout(node.tout); } node.mydbConfig.removeAllListeners(); node.status({}); }); diff --git a/storage/mysql/package.json b/storage/mysql/package.json index 9714c578..5bb89701 100644 --- a/storage/mysql/package.json +++ b/storage/mysql/package.json @@ -1,6 +1,6 @@ { "name" : "node-red-node-mysql", - "version" : "0.0.17", + "version" : "0.0.18", "description" : "A Node-RED node to read and write to a MySQL database", "dependencies" : { "mysql" : "^2.16.0"