Changeset

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
parents 8400:518b56d806bd
children 8402:469afa02947b
files util/pubsub.lua
diffstat 1 files changed, 7 insertions(+), 7 deletions(-) [+]
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