Software / code / prosody
Comparison
plugins/mod_storage_internal.lua @ 8393:b6a7b83f8d87
mod_storage_internal: Allow truncating deletion at the beginning or end of an archive store
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 09 Nov 2017 01:42:01 +0100 |
| parent | 8310:1759491b53db |
| child | 8394:4892c22403d5 |
comparison
equal
deleted
inserted
replaced
| 8392:ff8e122526f4 | 8393:b6a7b83f8d87 |
|---|---|
| 189 if query["end"] then | 189 if query["end"] then |
| 190 items:filter(function (item) | 190 items:filter(function (item) |
| 191 return item.when > query["end"]; | 191 return item.when > query["end"]; |
| 192 end); | 192 end); |
| 193 end | 193 end |
| 194 if query.truncate then | |
| 195 if query.reverse then | |
| 196 -- Before: { 1, 2, 3, 4, 5, } | |
| 197 -- After: { 1, 2, 3 } | |
| 198 while #items > query.truncate do | |
| 199 table.remove(items); | |
| 200 end | |
| 201 else | |
| 202 -- Before: { 1, 2, 3, 4, 5, } | |
| 203 -- After: { 3, 4, 5 } | |
| 204 while #items > query.truncate do | |
| 205 table.remove(items, 1); | |
| 206 end | |
| 207 end | |
| 208 end | |
| 194 end | 209 end |
| 195 local count = count_before - #items; | 210 local count = count_before - #items; |
| 196 local ok, err = datamanager.list_store(username, host, self.store, items); | 211 local ok, err = datamanager.list_store(username, host, self.store, items); |
| 197 if not ok then return ok, err; end | 212 if not ok then return ok, err; end |
| 198 return count; | 213 return count; |