Diff

util/pubsub.lua @ 8950:03ba5b4f131a

util.pubsub: Fix applying per service node defaults when loading from nodestore
author Kim Alvefur <zash@zash.se>
date Sun, 01 Jul 2018 04:17:36 +0200
parent 8941:f0beba9c2822
child 8951:9baac001fccb
line wrap: on
line diff
--- a/util/pubsub.lua	Sun Jul 01 03:43:14 2018 +0200
+++ b/util/pubsub.lua	Sun Jul 01 04:17:36 2018 +0200
@@ -21,14 +21,14 @@
 
 -- Storage helper functions
 
-local function load_node_from_store(nodestore, node_name)
-	local node = nodestore:get(node_name);
-	node.config = setmetatable(node.config or {}, default_node_config_mt);
+local function load_node_from_store(service, node_name)
+	local node = service.config.nodestore:get(node_name);
+	node.config = setmetatable(node.config or {}, {__index=service.node_defaults});
 	return node;
 end
 
-local function save_node_to_store(nodestore, node)
-	return nodestore:set(node.name, {
+local function save_node_to_store(service, node)
+	return service.config.nodestore:set(node.name, {
 		name = node.name;
 		config = node.config;
 		subscribers = node.subscribers;
@@ -53,7 +53,7 @@
 	-- Load nodes from storage, if we have a store and it supports iterating over stored items
 	if config.nodestore and config.nodestore.users then
 		for node_name in config.nodestore:users() do
-			service.nodes[node_name] = load_node_from_store(config.nodestore, node_name);
+			service.nodes[node_name] = load_node_from_store(service, node_name);
 			service.data[node_name] = config.itemstore(service.nodes[node_name].config, node_name);
 		end
 	end
@@ -254,7 +254,7 @@
 	};
 
 	if self.config.nodestore then
-		local ok, err = save_node_to_store(self.config.nodestore, self.nodes[node]);
+		local ok, err = save_node_to_store(self, self.nodes[node]);
 		if not ok then
 			self.nodes[node] = nil;
 			return ok, err;