aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_pep.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-11-04 00:35:44 +0100
committerKim Alvefur <zash@zash.se>2021-11-04 00:35:44 +0100
commitcc03265206ff7c693d8139bf3babfc9ace9b3928 (patch)
treeca6e2830fdc7d019745c749060e1bea27a64bb64 /plugins/mod_pep.lua
parenta4491e8bd952060fe5783332763ebb7726c55a4b (diff)
downloadprosody-cc03265206ff7c693d8139bf3babfc9ace9b3928.tar.gz
prosody-cc03265206ff7c693d8139bf3babfc9ace9b3928.zip
mod_pep: Limit possible growth of number of pubsub services
Diffstat (limited to 'plugins/mod_pep.lua')
-rw-r--r--plugins/mod_pep.lua18
1 files changed, 16 insertions, 2 deletions
diff --git a/plugins/mod_pep.lua b/plugins/mod_pep.lua
index 5d51f196..afa3a38b 100644
--- a/plugins/mod_pep.lua
+++ b/plugins/mod_pep.lua
@@ -18,8 +18,20 @@ local lib_pubsub = module:require "pubsub";
local empty_set = set_new();
+-- username -> object passed to module:add_items()
+local pep_service_items = {};
+
+-- size of caches with full pubsub service objects
+local service_cache_size = module:get_option_number("pep_service_cache_size", 1000);
+
-- username -> util.pubsub service object
-local services = {};
+local services = cache.new(service_cache_size, function (username, _)
+ local item = pep_service_items[username];
+ pep_service_items[username] = nil;
+ if item then
+ module:remove_item("pep-service", item);
+ end
+end):table();
-- username -> recipient -> set of nodes
local recipients = {};
@@ -202,7 +214,9 @@ function get_pep_service(username)
check_node_config = check_node_config;
});
services[username] = service;
- module:add_item("pep-service", { service = service, jid = user_bare });
+ local item = { service = service, jid = user_bare }
+ pep_service_items[username] = item;
+ module:add_item("pep-service", item);
return service;
end