Software /
code /
prosody
Changeset
9997:7c4631d7b6fb
mod_storage_internal,memory: Only return total count if requested
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 05 May 2019 08:12:16 +0200 |
parents | 9996:9bb1bed3e8e3 |
children | 9999:d2febb4befbc |
files | plugins/mod_storage_internal.lua plugins/mod_storage_memory.lua |
diffstat | 2 files changed, 23 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_storage_internal.lua Sat May 04 04:48:40 2019 +0200 +++ b/plugins/mod_storage_internal.lua Sun May 05 08:12:16 2019 +0200 @@ -124,11 +124,14 @@ if not items then if err then return items, err; - else - return function () end, 0; + elseif query then + if query.total then + return function () end, 0; + end end + return function () end; end - local count = #items; + local count = nil; local i = 0; if query then items = array(items); @@ -152,11 +155,13 @@ return item.when <= query["end"]; end); end - count = #items; + if query.total then + count = #items; + end if query.reverse then items:reverse(); if query.before then - for j = 1, count do + for j = 1, #items do if (items[j].key or tostring(j)) == query.before then i = j; break; @@ -164,7 +169,7 @@ end end elseif query.after then - for j = 1, count do + for j = 1, #items do if (items[j].key or tostring(j)) == query.after then i = j; break;
--- a/plugins/mod_storage_memory.lua Sat May 04 04:48:40 2019 +0200 +++ b/plugins/mod_storage_memory.lua Sun May 05 08:12:16 2019 +0200 @@ -90,9 +90,14 @@ function archive_store:find(username, query) local items = self.store[username or NULL]; if not items then - return function () end, 0; + if query then + if query.total then + return function () end, 0; + end + end + return function () end; end - local count = #items; + local count = nil; local i = 0; if query then items = array():append(items); @@ -116,11 +121,13 @@ return item.when <= query["end"]; end); end - count = #items; + if query.total then + count = #items; + end if query.reverse then items:reverse(); if query.before then - for j = 1, count do + for j = 1, #items do if (items[j].key or tostring(j)) == query.before then i = j; break; @@ -128,7 +135,7 @@ end end elseif query.after then - for j = 1, count do + for j = 1, #items do if (items[j].key or tostring(j)) == query.after then i = j; break;