Changeset

8952:15bb54f96dd1

util.pubsub: Remove node from persistent storage on deletion
author Kim Alvefur <zash@zash.se>
date Sun, 01 Jul 2018 04:46:37 +0200
parents 8951:9baac001fccb
children 8953:19cbe80df9c8
files util/pubsub.lua
diffstat 1 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/util/pubsub.lua	Sun Jul 01 04:27:09 2018 +0200
+++ b/util/pubsub.lua	Sun Jul 01 04:46:37 2018 +0200
@@ -36,6 +36,10 @@
 	});
 end
 
+local function delete_node_in_store(service, node_name)
+	return service.config.nodestore:set(node_name, nil);
+end
+
 -- Create and return a new service object
 local function new(config)
 	config = config or {};
@@ -290,6 +294,15 @@
 		self.data[node]:clear();
 	end
 	self.data[node] = nil;
+
+	if self.config.nodestore then
+		local ok, err = delete_node_in_store(self, node);
+		if not ok then
+			self.nodes[node] = nil;
+			return ok, err;
+		end
+	end
+
 	self.events.fire_event("node-deleted", { node = node, actor = actor });
 	self.config.broadcaster("delete", node, node_obj.subscribers, nil, actor, node_obj, self);
 	return true;