Software /
code /
prosody
Changeset
7696:1c410b4f3a58
util.pubsub: Factor item storage cache into a per service configurable option
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 16 Oct 2016 00:36:05 +0200 |
parents | 7695:56ce32cfd6d9 |
children | 7697:bd854e762875 7698:edacd0bef0e8 |
files | util/pubsub.lua |
diffstat | 1 files changed, 4 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/util/pubsub.lua Sun Oct 16 00:30:02 2016 +0200 +++ b/util/pubsub.lua Sun Oct 16 00:36:05 2016 +0200 @@ -5,6 +5,7 @@ local service_mt = { __index = service }; local default_config = { __index = { + itemstore = function (config) return cache.new(tonumber(config["pubsub#max_items"])) end; broadcaster = function () end; get_affiliation = function () end; capabilities = {}; @@ -222,7 +223,7 @@ config = setmetatable(options or {}, {__index=self.node_defaults}); affiliations = {}; }; - self.data[node] = cache.new(self.nodes[node].config["pubsub#max_items"]); + self.data[node] = self.config.itemstore(self.nodes[node].config); self.events.fire_event("node-created", { node = node, actor = actor }); local ok, err = self:set_affiliation(node, true, actor, "owner"); if not ok then @@ -307,7 +308,7 @@ if not node_obj then return false, "item-not-found"; end - self.data[node] = cache.new(node_obj.config["pubsub#max_items"]); -- Purge + self.data[node] = self.config.itemstore(self.nodes[node].config); self.events.fire_event("node-purged", { node = node, actor = actor }); if notify then self.config.broadcaster("purge", node, node_obj.subscribers); @@ -422,7 +423,7 @@ for k,v in pairs(new_config) do node_obj.config[k] = v; end - local new_data = cache.new(node_obj.config["pubsub#max_items"]); + local new_data = self.config.itemstore(self.nodes[node].config); for key, value in self.data[node]:items() do new_data:set(key, value); end