Skip to content

Commit b9394f0

Browse files
committed
(bluefox) do not store logs and messages and just publish it
(bluefox) remove mochawsome
1 parent 9a2e678 commit b9394f0

File tree

4 files changed

+72
-59
lines changed

4 files changed

+72
-59
lines changed

lib/states/statesInMemClient.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ function StatesInMemClient(settings) {
228228
client.emit('getMessage', id, callback);
229229
};
230230

231-
this.delMessage = function (id, messageId) {
231+
this.delMessage = function (id, messageId, callback) {
232232
if (!client) return;
233-
client.emit('delMessage', id, messageId);
233+
client.emit('delMessage', id, messageId, callback);
234234
};
235235

236236
this.subscribeMessage = function (pattern, callback) {
@@ -264,9 +264,9 @@ function StatesInMemClient(settings) {
264264
client.emit('getLog', id, callback);
265265
};
266266

267-
this.delLog = function (id, logId) {
267+
this.delLog = function (id, logId, callback) {
268268
if (!client) return;
269-
client.emit('delLog', id, logId);
269+
client.emit('delLog', id, logId, callback);
270270
};
271271

272272
this.subscribeLog = function (pattern, callback) {

lib/states/statesInMemServer.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ function StatesInMemory(settings) {
425425
socket.on('getMessage', function (id, callback) {
426426
that.getMessage.apply(that, arguments);
427427
});
428-
socket.on('delMessage', function (id, logId) {
428+
socket.on('delMessage', function (id, messageId, callback) {
429429
that.delMessage.apply(that, arguments);
430430
});
431431
socket.on('subscribeMessage', function (id, callback) {
@@ -443,7 +443,7 @@ function StatesInMemory(settings) {
443443
socket.on('getLog', function (id, callback) {
444444
that.getLog.apply(that, arguments);
445445
});
446-
socket.on('delLog', function (id, logId) {
446+
socket.on('delLog', function (id, logId, callback) {
447447
that.delLog.apply(that, arguments);
448448
});
449449
socket.on('subscribeLog', function (id, callback) {
@@ -782,10 +782,10 @@ function StatesInMemory(settings) {
782782
};
783783
*/
784784
this.pushMessage = function (id, state, callback) {
785-
messagebox[id] = messagebox[id] || [];
785+
//messagebox[id] = messagebox[id] || [];
786786
state._id = globalMessageId++;
787787
if (globalMessageId >= 0xFFFFFFFF) globalMessageId = 0;
788-
messagebox[id].unshift(state);
788+
//messagebox[id].unshift(state);
789789
that.publishAll('messagebox', 'messagebox.' + id, state);
790790
if (typeof callback === 'function') callback(null, id);
791791
};
@@ -806,7 +806,7 @@ function StatesInMemory(settings) {
806806
}
807807
};
808808

809-
this.delMessage = function (id, messageId) {
809+
this.delMessage = function (id, messageId, callback) {
810810
if (messagebox[id]) {
811811
var found = false;
812812
for (var i = messagebox[id].length - 1; i >= 0; i--) {
@@ -819,7 +819,12 @@ function StatesInMemory(settings) {
819819
if (!found) {
820820
console.log('WARNING: cannot find message with id = ' + messageId);
821821
log.error(namespace + ' WARNING: cannot find message with id = ' + messageId);
822+
if (typeof callback === 'function') callback('Not exists');
823+
} else {
824+
if (typeof callback === 'function') callback();
822825
}
826+
} else {
827+
if (typeof callback === 'function') callback();
823828
}
824829
};
825830

@@ -832,13 +837,14 @@ function StatesInMemory(settings) {
832837
};
833838

834839
this.pushLog = function (id, state, callback) {
835-
logs[id] = logs[id] || [];
840+
// do not store messages.
841+
//logs[id] = logs[id] || [];
836842
state._id = globalLogId++;
837843
if (globalLogId >= 0xFFFFFFFF) globalLogId = 0;
838-
logs[id].unshift(state);
839-
if (logs[id].length > settings.connection.maxQueue) {
840-
logs[id].splice(settings.connection.maxQueue - logs[id].length);
841-
}
844+
//logs[id].unshift(state);
845+
//if (logs[id].length > settings.connection.maxQueue) {
846+
// logs[id].splice(settings.connection.maxQueue - logs[id].length);
847+
//}
842848
that.publishAll('log', 'log.' + id, state);
843849
if (typeof callback === 'function') callback(null, id);
844850
};
@@ -859,7 +865,7 @@ function StatesInMemory(settings) {
859865
}
860866
};
861867

862-
this.delLog = function (id, logId) {
868+
this.delLog = function (id, logId, callback) {
863869
if (logs[id]) {
864870
var found = false;
865871
for (var i = logs[id].length - 1; i >= 0; i--) {
@@ -876,7 +882,12 @@ function StatesInMemory(settings) {
876882
log.error(namespace + ' WARNING: cannot find logs with id = ' + logId);
877883
logs[id].splice(100, logs[id].length - 100);
878884
}
885+
if (typeof callback === 'function') callback('Not exists');
886+
} else {
887+
if (typeof callback === 'function') callback();
879888
}
889+
} else if (typeof callback === 'function') {
890+
callback('Not exists');
880891
}
881892
};
882893

lib/states/statesInRedis.js

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -420,58 +420,61 @@ function StateRedis(settings) {
420420
this.pushMessage = function (id, state, callback) {
421421
state._id = globalMessageId++;
422422
if (globalMessageId >= 0xFFFFFFFF) globalMessageId = 0;
423-
client.lpush(namespaceMsg + id, JSON.stringify(state), function (err, obj) {
424-
client.ltrim(0, settings.connection.maxQueue - 1, function (err) {
423+
//client.lpush(namespaceMsg + id, JSON.stringify(state), function (err, obj) {
424+
//client.ltrim(0, settings.connection.maxQueue - 1, function (err) {
425425
// publish event in redis
426426
//log.debug('redis publish ' + namespaceMsg + id + ' ' + JSON.stringify(state));
427427
client.publish(namespaceMsg + id, JSON.stringify(state));
428428
if (typeof callback === 'function') callback(err, obj);
429-
});
430-
});
429+
//});
430+
//});
431431
};
432432

433433
this.lenMessage = function (id, callback) {
434-
client.llen(namespaceMsg + id, function (err, obj) {
435-
if (typeof callback === 'function') callback(err, obj);
436-
});
434+
if (typeof callback === 'function') callback(err, 0);
435+
//client.llen(namespaceMsg + id, function (err, obj) {
436+
// if (typeof callback === 'function') callback(err, obj);
437+
//});
437438
};
438439

439440
this.getMessage = function (id, callback) {
440-
client.lpop(namespaceMsg + id, function (err, obj) {
441-
if (typeof callback === 'function') {
442-
try {
443-
obj = obj ? JSON.parse(obj) : null;
444-
} catch (e) {
445-
obj = null;
446-
log.error(settings.namespace + ' Cannot parse messagebox object');
447-
}
448-
if (obj) {
449-
callback(err, obj);
450-
} else {
451-
callback('Cannot parse object', null);
452-
}
453-
}
454-
});
455-
};
456-
457-
this.delMessage = function (id, messageId) {
458-
client.lrange(namespaceMsg + id, 0, -1, function (err, obj) {
459-
if (obj) {
460-
var found = false;
461-
for (var i = 0; i < obj.length; i++) {
462-
// parse of object is 6 times slower
463-
if (messageId === null || obj[i].indexOf('"_id":' + messageId) != -1) {
464-
client.lrem(namespaceMsg + id, 1, obj[i]);
465-
found = true;
466-
break;
467-
}
468-
}
469-
if (!found) {
470-
console.log('WARNING: cannot find message with id = ' + messageId);
471-
log.error('WARNING: cannot find message with id = ' + messageId);
472-
}
473-
}
474-
});
441+
//client.lpop(namespaceMsg + id, function (err, obj) {
442+
// if (typeof callback === 'function') {
443+
// try {
444+
// obj = obj ? JSON.parse(obj) : null;
445+
// } catch (e) {
446+
// obj = null;
447+
// log.error(settings.namespace + ' Cannot parse messagebox object');
448+
// }
449+
// if (obj) {
450+
// callback(err, obj);
451+
// } else {
452+
// callback('Cannot parse object', null);
453+
// }
454+
// }
455+
//});
456+
if (typeof callback === 'function') callback(null, null);
457+
};
458+
459+
this.delMessage = function (id, messageId, callback) {
460+
//client.lrange(namespaceMsg + id, 0, -1, function (err, obj) {
461+
// if (obj) {
462+
// var found = false;
463+
// for (var i = 0; i < obj.length; i++) {
464+
// // parse of object is 6 times slower
465+
// if (messageId === null || obj[i].indexOf('"_id":' + messageId) != -1) {
466+
// client.lrem(namespaceMsg + id, 1, obj[i]);
467+
// found = true;
468+
// break;
469+
// }
470+
// }
471+
// if (!found) {
472+
// console.log('WARNING: cannot find message with id = ' + messageId);
473+
// log.error('WARNING: cannot find message with id = ' + messageId);
474+
// }
475+
// }
476+
//});
477+
if (typeof callback === 'function') callback();
475478
};
476479

477480
this.clearAllMessages = function (callback) {

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
"grunt-jsdoc": "^2.1.0",
4848
"mocha": "^2.3.4",
4949
"chai": "^3.4.1",
50-
"mochawesome": "^2.0.3",
5150
"istanbul": "^0.4.5"
5251
},
5352
"homepage": "http://www.iobroker.com",
@@ -91,7 +90,7 @@
9190
"stop": "node iobroker.js stop",
9291
"restart": "node iobroker.js restart",
9392
"prepublish": "node lib/scripts/scripts.js --prepublish",
94-
"test": "node node_modules/mocha/bin/mocha test --reporter mochawesome --reporter-options reportDir=test/report,reportName=report",
93+
"test": "node node_modules/mocha/bin/mocha test",
9594
"coverage": "node node_modules/istanbul/lib/cli.js cover --config istanbul.yml node_modules/mocha/bin/_mocha ./test -- --ui bdd -R spec"
9695
},
9796
"main": "controller.js",

0 commit comments

Comments
 (0)