# HG changeset patch # User Kim Alvefur # Date 1557036736 -7200 # Node ID 7c4631d7b6fbb53a2d1c055defa6a0187a8a0b8d # Parent 9bb1bed3e8e3a050af14b83c2c225346c8ee328d mod_storage_internal,memory: Only return total count if requested diff -r 9bb1bed3e8e3 -r 7c4631d7b6fb plugins/mod_storage_internal.lua --- 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; diff -r 9bb1bed3e8e3 -r 7c4631d7b6fb plugins/mod_storage_memory.lua --- 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;