Mercurial > prosody-hg
comparison plugins/mod_storage_memory.lua @ 10926:c55bd98a54f8
mod_storage_internal, mod_storage_memory: Add support for query.before
Previously returned all results.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 12 Jun 2020 16:55:35 +0100 |
| parents | 018acdaf374f |
| children | ecbfde402364 |
comparison
equal
deleted
inserted
replaced
| 10925:73e95ecec733 | 10926:c55bd98a54f8 |
|---|---|
| 99 end | 99 end |
| 100 end | 100 end |
| 101 return function () end; | 101 return function () end; |
| 102 end | 102 end |
| 103 local count = nil; | 103 local count = nil; |
| 104 local i = 0; | 104 local i, last_key = 0; |
| 105 if query then | 105 if query then |
| 106 items = array():append(items); | 106 items = array():append(items); |
| 107 if query.key then | 107 if query.key then |
| 108 items:filter(function (item) | 108 items:filter(function (item) |
| 109 return item.key == query.key; | 109 return item.key == query.key; |
| 140 end | 140 end |
| 141 if not found then | 141 if not found then |
| 142 return nil, "item-not-found"; | 142 return nil, "item-not-found"; |
| 143 end | 143 end |
| 144 end | 144 end |
| 145 elseif query.before then | |
| 146 last_key = query.before; | |
| 145 elseif query.after then | 147 elseif query.after then |
| 146 local found = false; | 148 local found = false; |
| 147 for j = 1, #items do | 149 for j = 1, #items do |
| 148 if (items[j].key or tostring(j)) == query.after then | 150 if (items[j].key or tostring(j)) == query.after then |
| 149 found = true; | 151 found = true; |
| 160 end | 162 end |
| 161 end | 163 end |
| 162 return function () | 164 return function () |
| 163 i = i + 1; | 165 i = i + 1; |
| 164 local item = items[i]; | 166 local item = items[i]; |
| 165 if not item then return; end | 167 if not item or (last_key and item.key == last_key) then return; end |
| 166 return item.key, item.value(), item.when, item.with; | 168 return item.key, item.value(), item.when, item.with; |
| 167 end, count; | 169 end, count; |
| 168 end | 170 end |
| 169 | 171 |
| 170 function archive_store:get(username, wanted_key) | 172 function archive_store:get(username, wanted_key) |
