mod_pep_plus: Make node persistence configurable via pubsub#persist_items
authorKim Alvefur <zash@zash.se>
Thu, 12 Oct 2017 01:37:35 +0200
changeset 8323 fe5eaf4ed631
parent 8322 57e3ad11f3f6
child 8324 73ff49a42ea8
mod_pep_plus: Make node persistence configurable via pubsub#persist_items
plugins/mod_pep_plus.lua
plugins/mod_pubsub/pubsub.lib.lua
--- a/plugins/mod_pep_plus.lua	Thu Oct 12 01:34:32 2017 +0200
+++ b/plugins/mod_pep_plus.lua	Thu Oct 12 01:37:35 2017 +0200
@@ -6,6 +6,7 @@
 local st = require "util.stanza";
 local calculate_hash = require "util.caps".calculate_hash;
 local is_contact_subscribed = require "core.rostermanager".is_contact_subscribed;
+local cache = require "util.cache";
 
 local xmlns_pubsub = "http://jabber.org/protocol/pubsub";
 local xmlns_pubsub_event = "http://jabber.org/protocol/pubsub#event";
@@ -42,10 +43,16 @@
 
 local function simple_itemstore(username)
 	return function (config, node)
-		module:log("debug", "new simple_itemstore(%q, %q)", username, node);
-		known_nodes_map:set(username, node, true);
-		local archive = module:open_store("pep_"..node, "archive");
-		return lib_pubsub.archive_itemstore(archive, config, username, node, false);
+		if config["pubsub#persist_items"] then
+			module:log("debug", "Creating new persistent item store for user %s, node %q", username, node);
+			known_nodes_map:set(username, node, true);
+			local archive = module:open_store("pep_"..node, "archive");
+			return lib_pubsub.archive_itemstore(archive, config, username, node, false);
+		else
+			module:log("debug", "Creating new ephemeral item store for user %s, node %q", username, node);
+			known_nodes_map:set(username, node, nil);
+			return cache.new(tonumber(config["pubsub#max_items"]));
+		end
 	end
 end
 
@@ -173,6 +180,7 @@
 
 		node_defaults = {
 			["pubsub#max_items"] = "1";
+			["pubsub#persist_items"] = true;
 		};
 
 		autocreate_on_publish = true;
--- a/plugins/mod_pubsub/pubsub.lib.lua	Thu Oct 12 01:34:32 2017 +0200
+++ b/plugins/mod_pubsub/pubsub.lib.lua	Thu Oct 12 01:37:35 2017 +0200
@@ -45,6 +45,11 @@
 		name = "pubsub#max_items";
 		label = "Max # of items to persist";
 	};
+	{
+		type = "boolean";
+		name = "pubsub#persist_items";
+		label = "Persist items to storage";
+	};
 };
 
 function handlers.get_items(origin, stanza, items, service)