# HG changeset patch # User Kim Alvefur # Date 1530411456 -7200 # Node ID 03ba5b4f131acfd756d09c5229b80aa852d17cb3 # Parent 9194431b64478536fa3f50eaa798ff4c9e8628b9 util.pubsub: Fix applying per service node defaults when loading from nodestore diff -r 9194431b6447 -r 03ba5b4f131a util/pubsub.lua --- 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;