Software /
code /
prosody
Changeset
12153:26af75c20163
util.pubsub: Fix item store resize to "max"
Previously this would end up passing the "max" directly to the
underlying storage.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 06 Jan 2022 01:18:35 +0100 |
parents | 12152:0939675955f1 |
children | 12154:760dd1fc3dc1 |
files | plugins/mod_pep.lua plugins/mod_pubsub/mod_pubsub.lua spec/util_pubsub_spec.lua util/pubsub.lua |
diffstat | 4 files changed, 28 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_pep.lua Thu Jan 06 00:59:40 2022 +0100 +++ b/plugins/mod_pep.lua Thu Jan 06 01:18:35 2022 +0100 @@ -221,6 +221,7 @@ ["access_model"] = "presence"; ["send_last_published_item"] = "on_sub_and_presence"; }; + max_items = max_max_items; autocreate_on_publish = true; autocreate_on_subscribe = false;
--- a/plugins/mod_pubsub/mod_pubsub.lua Thu Jan 06 00:59:40 2022 +0100 +++ b/plugins/mod_pubsub/mod_pubsub.lua Thu Jan 06 01:18:35 2022 +0100 @@ -224,6 +224,7 @@ node_defaults = { ["persist_items"] = true; }; + max_items = max_max_items; nodestore = node_store; itemstore = create_simple_itemstore; broadcaster = simple_broadcast;
--- a/spec/util_pubsub_spec.lua Thu Jan 06 00:59:40 2022 +0100 +++ b/spec/util_pubsub_spec.lua Thu Jan 06 01:18:35 2022 +0100 @@ -169,6 +169,26 @@ }, ret); end); + it("has a default max_items", function () + assert.truthy(service.config.max_items); + end) + + it("changes max_items to max", function () + assert.truthy(service:set_node_config("node", true, { max_items = "max" })); + end); + + it("publishes some more items", function() + for i = 4, service.config.max_items + 5 do + assert.truthy(service:publish("node", true, tostring(i), "item " .. tostring(i))); + end + end); + + it("should still return only two items", function () + local ok, ret = service:get_items("node", true); + assert.truthy(ok); + assert.same(service.config.max_items, #ret); + end); + end); describe("the thing", function ()
--- a/util/pubsub.lua Thu Jan 06 00:59:40 2022 +0100 +++ b/util/pubsub.lua Thu Jan 06 01:18:35 2022 +0100 @@ -5,6 +5,7 @@ local service_mt = {}; local default_config = { + max_items = 256; itemstore = function (config, _) return cache.new(config["max_items"]) end; broadcaster = function () end; subscriber_filter = function (subs) return subs end; @@ -841,7 +842,11 @@ end elseif old_config["max_items"] ~= node_obj.config["max_items"] then if self.data[node] then - self.data[node]:resize(self.nodes[node].config["max_items"]); + local max_items = self.nodes[node].config["max_items"]; + if max_items == "max" then + max_items = self.config.max_items; + end + self.data[node]:resize(max_items); end end