aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-09-05 16:21:10 +0200
committerKim Alvefur <zash@zash.se>2021-09-05 16:21:10 +0200
commit1546e59310f4eb2888227a0f09a4554cc7da145d (patch)
tree2cf3abe2e38a012381c77a000efb42bdbb5bfa7d /util
parente3c0a877bf2eaf1f5c3f150ad66de0af331e885b (diff)
downloadprosody-1546e59310f4eb2888227a0f09a4554cc7da145d.tar.gz
prosody-1546e59310f4eb2888227a0f09a4554cc7da145d.zip
util.pubsub: Add support for limiting number of items to retrieve
Hopefully this will eventually be upgraded to RSM, which is why the argument is called 'resultspec' and is a table.
Diffstat (limited to 'util')
-rw-r--r--util/pubsub.lua7
1 files changed, 6 insertions, 1 deletions
diff --git a/util/pubsub.lua b/util/pubsub.lua
index ae1d6353..e23818b8 100644
--- a/util/pubsub.lua
+++ b/util/pubsub.lua
@@ -642,7 +642,7 @@ function service:purge(node, actor, notify) --> ok, err
return true
end
-function service:get_items(node, actor, ids) --> (true, { id, [id] = node }) or (false, err)
+function service:get_items(node, actor, ids, resultspec) --> (true, { id, [id] = node }) or (false, err)
-- Access checking
if not self:may(node, actor, "get_items") then
return false, "forbidden";
@@ -660,18 +660,23 @@ function service:get_items(node, actor, ids) --> (true, { id, [id] = node }) or
ids = { ids };
end
local data = {};
+ local limit = resultspec and resultspec.max;
if ids then
for _, key in ipairs(ids) do
local value = self.data[node]:get(key);
if value then
data[#data+1] = key;
data[key] = value;
+ -- Limits and ids seem like a problematic combination.
+ if limit and #data >= limit then break end
end
end
else
for key, value in self.data[node]:items() do
data[#data+1] = key;
data[key] = value;
+ if limit and #data >= limit then break
+ end
end
end
return true, data;