Diff

util/pubsub.lua @ 8401:f1923a79c93d

util.pubsub: Recreate itemstore if persist_items changes or resize it if max_items changes
author Kim Alvefur <zash@zash.se>
date Thu, 09 Nov 2017 17:19:11 +0100
parent 8382:e5d00bf4a4d5
child 8500:9bf00d0734c8
line wrap: on
line diff
--- a/util/pubsub.lua	Thu Nov 09 17:22:47 2017 +0100
+++ b/util/pubsub.lua	Thu Nov 09 17:19:11 2017 +0100
@@ -431,14 +431,14 @@
 		return false, "item-not-found";
 	end
 
-	for k,v in pairs(new_config) do
-		node_obj.config[k] = v;
+	if new_config["persist_items"] ~= node_obj.config["persist_items"] then
+		self.data[node] = self.config.itemstore(self.nodes[node].config, node);
+	elseif new_config["max_items"] ~= node_obj.config["max_items"] then
+		self.data[node]:resize(new_config["max_items"]);
 	end
-	local new_data = self.config.itemstore(self.nodes[node].config, node);
-	for key, value in self.data[node]:items() do
-		new_data:set(key, value);
-	end
-	self.data[node] = new_data;
+
+	node_obj.config = setmetatable(new_config, {__index=self.node_defaults});
+
 	return true;
 end