Skip to content

Commit

Permalink
Merge pull request #21 from mcollina/qlobber-sub-count
Browse files Browse the repository at this point in the history
Count offline subscriptions in QlobberSub
  • Loading branch information
mcollina authored Aug 15, 2017
2 parents 465e60a + 034081c commit d13d47f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"aedes-packet": "^1.0.0",
"from2": "^2.1.0",
"qlobber": "^1.5.0",
"qlobber": "^1.8.0",
"safe-buffer": "^5.0.1"
}
}
9 changes: 1 addition & 8 deletions persistence.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function MemoryPersistence () {
this._retained = []
// clientId -> topic -> qos
this._subscriptions = new Map()
this._subscriptionsCount = 0
this._clientsCount = 0
this._trie = new QlobberSub(QlobberOpts)
this._outgoing = {}
Expand Down Expand Up @@ -87,9 +86,6 @@ MemoryPersistence.prototype.addSubscriptions = function (client, subs, cb) {
var qos = stored.get(sub.topic)
var hasQoSGreaterThanZero = (qos !== undefined) && (qos > 0)
if (sub.qos > 0) {
if (!hasQoSGreaterThanZero) {
this._subscriptionsCount++
}
trie.add(sub.topic, {
clientId: client.id,
topic: sub.topic,
Expand All @@ -100,7 +96,6 @@ MemoryPersistence.prototype.addSubscriptions = function (client, subs, cb) {
clientId: client.id,
topic: sub.topic
})
this._subscriptionsCount--
}
stored.set(sub.topic, sub.qos)
}
Expand All @@ -118,7 +113,6 @@ MemoryPersistence.prototype.removeSubscriptions = function (client, subs, cb) {
var qos = stored.get(topic)
if (qos !== undefined) {
if (qos > 0) {
this._subscriptionsCount--
trie.remove(topic, { clientId: client.id, topic: topic })
}
stored.delete(topic)
Expand Down Expand Up @@ -147,7 +141,7 @@ MemoryPersistence.prototype.subscriptionsByClient = function (client, cb) {
}

MemoryPersistence.prototype.countOffline = function (cb) {
return cb(null, this._subscriptionsCount, this._clientsCount)
return cb(null, this._trie.subscriptionsCount, this._clientsCount)
}

MemoryPersistence.prototype.subscriptionsByTopic = function (pattern, cb) {
Expand All @@ -161,7 +155,6 @@ MemoryPersistence.prototype.cleanSubscriptions = function (client, cb) {
if (stored) {
for (var topicAndQos of stored) {
if (topicAndQos[1] > 0) {
this._subscriptionsCount--
var topic = topicAndQos[0]
trie.remove(topic, { clientId: client.id, topic: topic })
}
Expand Down

0 comments on commit d13d47f

Please sign in to comment.