aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-10-16 00:36:05 +0200
committerKim Alvefur <zash@zash.se>2016-10-16 00:36:05 +0200
commitffbc38cfa3aafd8cfeae06a4396d5a074ffebc7e (patch)
tree494335cc106313ce4f53ec9a5b85a0933bf0b0aa /util
parent8ebfeb497ea324ec565ffd65ada00e5b9de34eb8 (diff)
downloadprosody-ffbc38cfa3aafd8cfeae06a4396d5a074ffebc7e.tar.gz
prosody-ffbc38cfa3aafd8cfeae06a4396d5a074ffebc7e.zip
util.pubsub: Factor item storage cache into a per service configurable option
Diffstat (limited to 'util')
-rw-r--r--util/pubsub.lua7
1 files changed, 4 insertions, 3 deletions
diff --git a/util/pubsub.lua b/util/pubsub.lua
index b5cfdb6e..520d80a7 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -5,6 +5,7 @@ local service = {};
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 @@ function service:create(node, actor, options)
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 @@ function service:purge(node, actor, notify)
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 @@ function service:set_node_config(node, actor, new_config)
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