Software /
code /
prosody
Diff
util/pubsub.lua @ 11767:5610f7c5b261
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.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 05 Sep 2021 16:21:10 +0200 |
parent | 11723:3ead0967e04d |
child | 11854:b605cbd5f13b |
line wrap: on
line diff
--- a/util/pubsub.lua Wed Sep 01 19:05:24 2021 +0200 +++ b/util/pubsub.lua Sun Sep 05 16:21:10 2021 +0200 @@ -642,7 +642,7 @@ 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 @@ 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;