Mercurial > prosody-modules
comparison mod_storage_muc_log/mod_storage_muc_log.lua @ 2357:093b70378fa5
mod_storage_muc_log: Separate out date collection into API method
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 09 Nov 2016 13:38:44 +0100 |
| parents | 49a01b78b45f |
| children | f3a09a559201 |
comparison
equal
deleted
inserted
replaced
| 2356:49a01b78b45f | 2357:093b70378fa5 |
|---|---|
| 65 return ok, err; | 65 return ok, err; |
| 66 end | 66 end |
| 67 return today .. "_" .. #data; | 67 return today .. "_" .. #data; |
| 68 end | 68 end |
| 69 | 69 |
| 70 function driver:find(node, query) | 70 function driver:dates(node) |
| 71 local path = datamanager.getpath(node, host, datastore):match("(.*)/"); | 71 local path = datamanager.getpath(node, host, datastore):match("(.*)/"); |
| 72 | 72 |
| 73 local ok, iter, state, var = pcall(lfs.dir, path); | 73 local ok, iter, state, var = pcall(lfs.dir, path); |
| 74 if not ok then | 74 if not ok then |
| 75 module:log("warn", iter); | 75 module:log("warn", iter); |
| 82 dates[i], i = dir, i+1; | 82 dates[i], i = dir, i+1; |
| 83 end | 83 end |
| 84 end | 84 end |
| 85 if dates[1] == nil then return noop, 0; end | 85 if dates[1] == nil then return noop, 0; end |
| 86 table.sort(dates); | 86 table.sort(dates); |
| 87 return dates; | |
| 88 end | |
| 89 | |
| 90 function driver:find(node, query) | |
| 91 local dates, err = self:dates(node); | |
| 92 if not dates then return dates, err; end | |
| 87 | 93 |
| 88 return coroutine.wrap(function () | 94 return coroutine.wrap(function () |
| 89 local start_date = query and query.start and os_date(datef, query.start) or dates[1]; | 95 local start_date = query and query.start and os_date(datef, query.start) or dates[1]; |
| 90 local end_date = query and query["end"] and os_date(datef, query["end"]) or dates[#dates]; | 96 local end_date = query and query["end"] and os_date(datef, query["end"]) or dates[#dates]; |
| 91 local start_time = query and query.start and os_date(timef, query.start) or dates[1]; | 97 local start_time = query and query.start and os_date(timef, query.start) or dates[1]; |
