diff options
author | Matthew Wild <mwild1@gmail.com> | 2020-06-12 16:55:35 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2020-06-12 16:55:35 +0100 |
commit | 6a126c350f01160c7e4b03109b5e3a3f67d5d5bb (patch) | |
tree | a9f8657bc3fd1a166f49c958671e5b2a86f0f72a | |
parent | c96212e146b390739d411e5f7ba87429468a8462 (diff) | |
download | prosody-6a126c350f01160c7e4b03109b5e3a3f67d5d5bb.tar.gz prosody-6a126c350f01160c7e4b03109b5e3a3f67d5d5bb.zip |
mod_storage_internal, mod_storage_memory: Add support for query.before
Previously returned all results.
-rw-r--r-- | plugins/mod_storage_internal.lua | 8 | ||||
-rw-r--r-- | plugins/mod_storage_memory.lua | 6 |
2 files changed, 10 insertions, 4 deletions
diff --git a/plugins/mod_storage_internal.lua b/plugins/mod_storage_internal.lua index 3998165b..28dc8921 100644 --- a/plugins/mod_storage_internal.lua +++ b/plugins/mod_storage_internal.lua @@ -135,7 +135,7 @@ function archive:find(username, query) return function () end; end local count = nil; - local i = 0; + local i, last_key = 0; if query then items = array(items); if query.key then @@ -178,6 +178,8 @@ function archive:find(username, query) return nil, "item-not-found"; end end + elseif query.before then + last_key = query.before; elseif query.after then local found = false; for j = 1, #items do @@ -198,7 +200,9 @@ function archive:find(username, query) return function () i = i + 1; local item = items[i]; - if not item then return; end + if not item or (last_key and item.key == last_key) then + return; + end local key = item.key or tostring(i); local when = item.when or datetime.parse(item.attr.stamp); local with = item.with; diff --git a/plugins/mod_storage_memory.lua b/plugins/mod_storage_memory.lua index 67598416..d71dc0f0 100644 --- a/plugins/mod_storage_memory.lua +++ b/plugins/mod_storage_memory.lua @@ -101,7 +101,7 @@ function archive_store:find(username, query) return function () end; end local count = nil; - local i = 0; + local i, last_key = 0; if query then items = array():append(items); if query.key then @@ -142,6 +142,8 @@ function archive_store:find(username, query) return nil, "item-not-found"; end end + elseif query.before then + last_key = query.before; elseif query.after then local found = false; for j = 1, #items do @@ -162,7 +164,7 @@ function archive_store:find(username, query) return function () i = i + 1; local item = items[i]; - if not item then return; end + if not item or (last_key and item.key == last_key) then return; end return item.key, item.value(), item.when, item.with; end, count; end |