Software /
code /
prosody-modules
Diff
mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 2397:7f9bf161f640
mod_storage_xmlarchive: Open XML file later, just before it is needed
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 25 Nov 2016 23:11:07 +0100 |
parent | 2396:544ee057a23f |
child | 2398:7e922b968b44 |
line wrap: on
line diff
--- a/mod_storage_xmlarchive/mod_storage_xmlarchive.lua Fri Nov 25 23:08:18 2016 +0100 +++ b/mod_storage_xmlarchive/mod_storage_xmlarchive.lua Fri Nov 25 23:11:07 2016 +0100 @@ -118,13 +118,6 @@ else first_item, last_item = #items, 1; end - local ferr; - filename = dm.getpath(username .. "@" .. dates[d], module.host, self.store, "xml"); - xmlfile, ferr = io.open(filename); - if not xmlfile then - module:log("error", "Error: %s", ferr); - return; - end end local q_with, q_start, q_end = query.with, query.start, query["end"]; @@ -142,7 +135,16 @@ module:log("warn", "data[%q][%d].when is invalid", dates[d], i); break; end - if xmlfile and in_range + if not xmlfile then + local ferr; + filename = dm.getpath(username .. "@" .. dates[d], module.host, self.store, "xml"); + xmlfile, ferr = io.open(filename); + if not xmlfile then + module:log("error", "Error: %s", ferr); + return; + end + end + if in_range and (not q_with or i_with == q_with) and (not q_start or i_when >= q_start) and (not q_end or i_when <= q_end) then @@ -172,10 +174,10 @@ in_range = true; end end - end - if xmlfile then - xmlfile:close(); - xmlfile = nil; + if xmlfile then + xmlfile:close(); + xmlfile = nil; + end end end end