From e2c4ba472e9ca653420bd9a4d8f133f12bbaa7c3 Mon Sep 17 00:00:00 2001 From: Dimitris Date: Thu, 19 Oct 2017 14:06:40 +0300 Subject: [PATCH 1/3] fixes #693 --- lib/persistence/levelup.js | 9 +++++---- lib/persistence/mongo.js | 8 +++++--- lib/persistence/redis.js | 7 ++++--- test/persistence/abstract.js | 4 ++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/persistence/levelup.js b/lib/persistence/levelup.js index 788fc46..814fb89 100644 --- a/lib/persistence/levelup.js +++ b/lib/persistence/levelup.js @@ -162,11 +162,12 @@ LevelUpPersistence.prototype.storeSubscriptions = function(client, done) { var now = Date.now(); if (!client.clean) { + // Issue #693 Object.keys(client.subscriptions).forEach(function(key) { - if (client.subscriptions[key].qos > 0) { - subscriptions[key] = client.subscriptions[key]; - subscriptions[key].ttl = that.options.ttl.subscriptions + now; - } + //if (client.subscriptions[key].qos > 0) { // Issue #693 + subscriptions[key] = client.subscriptions[key]; + subscriptions[key].ttl = that.options.ttl.subscriptions + now; + //} // Issue #693 }); this._clientSubscriptions.put(client.id, subscriptions, done); Object.keys(subscriptions).forEach(function(key) { diff --git a/lib/persistence/mongo.js b/lib/persistence/mongo.js index 2462393..4681a9b 100644 --- a/lib/persistence/mongo.js +++ b/lib/persistence/mongo.js @@ -183,9 +183,11 @@ MongoPersistence.prototype.storeSubscriptions = function(client, done) { var that = this; if (!client.clean) { - subscriptions = Object.keys(client.subscriptions).filter(function(key) { - return client.subscriptions[key].qos > 0; - }); + // Issue #693 + // subscriptions = Object.keys(client.subscriptions).filter(function(key) { + // return client.subscriptions[key].qos > 0; + // }); + subscriptions = Object.keys(client.subscriptions); steed.each(subscriptions, function(key, cb) { that._subscriptions.findAndModify({ diff --git a/lib/persistence/redis.js b/lib/persistence/redis.js index bc90851..3d1dab0 100644 --- a/lib/persistence/redis.js +++ b/lib/persistence/redis.js @@ -283,10 +283,11 @@ RedisPersistence.prototype.storeSubscriptions = function(client, cb) { var that = this; var subscriptions = {}; + // Issue #693 Object.keys(client.subscriptions).forEach(function(key) { - if (client.subscriptions[key].qos > 0) { - subscriptions[key] = client.subscriptions[key]; - } + // if (client.subscriptions[key].qos > 0) { // Issue #693 + subscriptions[key] = client.subscriptions[key]; + //} // Issue #693 }); this._client.get(clientSubKey, function(err, currentSubs){ diff --git a/test/persistence/abstract.js b/test/persistence/abstract.js index d3100b9..4085126 100644 --- a/test/persistence/abstract.js +++ b/test/persistence/abstract.js @@ -558,7 +558,7 @@ module.exports = function(create, buildOpts) { }); }); - it("should not store a QoS 0 subscription", function(done) { + it("should store a QoS 0 subscription", function(done) { var instance = this.instance; var client = { id: "my client id - 42", @@ -573,7 +573,7 @@ module.exports = function(create, buildOpts) { instance.storeSubscriptions(client, function() { instance.lookupSubscriptions(client, function(err, results) { - expect(results).to.eql({}); + expect(results).to.eql(client.subscriptions); done(); }); }); From 0bfb41c273e464a5f3addf220f901fe2edd1fce0 Mon Sep 17 00:00:00 2001 From: Dimitris Date: Mon, 23 Oct 2017 11:14:49 +0300 Subject: [PATCH 2/3] Just to push --- test/persistence/mongo_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/persistence/mongo_spec.js b/test/persistence/mongo_spec.js index 960e1c9..1ad7869 100644 --- a/test/persistence/mongo_spec.js +++ b/test/persistence/mongo_spec.js @@ -88,7 +88,7 @@ describe("mosca.persistence.Mongo", function() { var packet = { topic: "hello/42", qos: 0, - payload: 'someStringToTest', // not a buffer + payload: 'someStringToTest', // not a Buffer messageId: 42 }; From 9d7c706165bc8b8cdfc6cc4dd12cc267d07be24f Mon Sep 17 00:00:00 2001 From: Dimitris Date: Fri, 27 Oct 2017 20:25:41 +0300 Subject: [PATCH 3/3] removed comments --- lib/persistence/levelup.js | 2 -- lib/persistence/redis.js | 2 -- 2 files changed, 4 deletions(-) diff --git a/lib/persistence/levelup.js b/lib/persistence/levelup.js index 814fb89..a5a2d23 100644 --- a/lib/persistence/levelup.js +++ b/lib/persistence/levelup.js @@ -164,10 +164,8 @@ LevelUpPersistence.prototype.storeSubscriptions = function(client, done) { if (!client.clean) { // Issue #693 Object.keys(client.subscriptions).forEach(function(key) { - //if (client.subscriptions[key].qos > 0) { // Issue #693 subscriptions[key] = client.subscriptions[key]; subscriptions[key].ttl = that.options.ttl.subscriptions + now; - //} // Issue #693 }); this._clientSubscriptions.put(client.id, subscriptions, done); Object.keys(subscriptions).forEach(function(key) { diff --git a/lib/persistence/redis.js b/lib/persistence/redis.js index 3d1dab0..e18d077 100644 --- a/lib/persistence/redis.js +++ b/lib/persistence/redis.js @@ -285,9 +285,7 @@ RedisPersistence.prototype.storeSubscriptions = function(client, cb) { // Issue #693 Object.keys(client.subscriptions).forEach(function(key) { - // if (client.subscriptions[key].qos > 0) { // Issue #693 subscriptions[key] = client.subscriptions[key]; - //} // Issue #693 }); this._client.get(clientSubKey, function(err, currentSubs){