Mercurial > prosody-hg
comparison plugins/mod_storage_internal.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 | 05f4386c846e |
| children | b8fada57faf0 |
comparison
equal
deleted
inserted
replaced
| 10925:73e95ecec733 | 10926:c55bd98a54f8 |
|---|---|
| 133 end | 133 end |
| 134 end | 134 end |
| 135 return function () end; | 135 return function () end; |
| 136 end | 136 end |
| 137 local count = nil; | 137 local count = nil; |
| 138 local i = 0; | 138 local i, last_key = 0; |
| 139 if query then | 139 if query then |
| 140 items = array(items); | 140 items = array(items); |
| 141 if query.key then | 141 if query.key then |
| 142 items:filter(function (item) | 142 items:filter(function (item) |
| 143 return item.key == query.key; | 143 return item.key == query.key; |
| 176 end | 176 end |
| 177 if not found then | 177 if not found then |
| 178 return nil, "item-not-found"; | 178 return nil, "item-not-found"; |
| 179 end | 179 end |
| 180 end | 180 end |
| 181 elseif query.before then | |
| 182 last_key = query.before; | |
| 181 elseif query.after then | 183 elseif query.after then |
| 182 local found = false; | 184 local found = false; |
| 183 for j = 1, #items do | 185 for j = 1, #items do |
| 184 if (items[j].key or tostring(j)) == query.after then | 186 if (items[j].key or tostring(j)) == query.after then |
| 185 found = true; | 187 found = true; |
| 196 end | 198 end |
| 197 end | 199 end |
| 198 return function () | 200 return function () |
| 199 i = i + 1; | 201 i = i + 1; |
| 200 local item = items[i]; | 202 local item = items[i]; |
| 201 if not item then return; end | 203 if not item or (last_key and item.key == last_key) then |
| 204 return; | |
| 205 end | |
| 202 local key = item.key or tostring(i); | 206 local key = item.key or tostring(i); |
| 203 local when = item.when or datetime.parse(item.attr.stamp); | 207 local when = item.when or datetime.parse(item.attr.stamp); |
| 204 local with = item.with; | 208 local with = item.with; |
| 205 item.key, item.when, item.with = nil, nil, nil; | 209 item.key, item.when, item.with = nil, nil, nil; |
| 206 item.attr.stamp = nil; | 210 item.attr.stamp = nil; |
