Software /
code /
prosody-modules
Comparison
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 |
comparison
equal
deleted
inserted
replaced
2396:544ee057a23f | 2397:7f9bf161f640 |
---|---|
116 if not rev then | 116 if not rev then |
117 first_item, last_item = 1, #items; | 117 first_item, last_item = 1, #items; |
118 else | 118 else |
119 first_item, last_item = #items, 1; | 119 first_item, last_item = #items, 1; |
120 end | 120 end |
121 local ferr; | |
122 filename = dm.getpath(username .. "@" .. dates[d], module.host, self.store, "xml"); | |
123 xmlfile, ferr = io.open(filename); | |
124 if not xmlfile then | |
125 module:log("error", "Error: %s", ferr); | |
126 return; | |
127 end | |
128 end | 121 end |
129 | 122 |
130 local q_with, q_start, q_end = query.with, query.start, query["end"]; | 123 local q_with, q_start, q_end = query.with, query.start, query["end"]; |
131 for i = first_item, last_item, step do | 124 for i = first_item, last_item, step do |
132 local item = items[i]; | 125 local item = items[i]; |
140 end | 133 end |
141 if type(i_when) ~= "number" then | 134 if type(i_when) ~= "number" then |
142 module:log("warn", "data[%q][%d].when is invalid", dates[d], i); | 135 module:log("warn", "data[%q][%d].when is invalid", dates[d], i); |
143 break; | 136 break; |
144 end | 137 end |
145 if xmlfile and in_range | 138 if not xmlfile then |
139 local ferr; | |
140 filename = dm.getpath(username .. "@" .. dates[d], module.host, self.store, "xml"); | |
141 xmlfile, ferr = io.open(filename); | |
142 if not xmlfile then | |
143 module:log("error", "Error: %s", ferr); | |
144 return; | |
145 end | |
146 end | |
147 if in_range | |
146 and (not q_with or i_with == q_with) | 148 and (not q_with or i_with == q_with) |
147 and (not q_start or i_when >= q_start) | 149 and (not q_start or i_when >= q_start) |
148 and (not q_end or i_when <= q_end) then | 150 and (not q_end or i_when <= q_end) then |
149 count = count + 1; | 151 count = count + 1; |
150 first_item = i + step; | 152 first_item = i + step; |
170 if (rev and item.id == query.before) or | 172 if (rev and item.id == query.before) or |
171 (not rev and item.id == query.after) then | 173 (not rev and item.id == query.after) then |
172 in_range = true; | 174 in_range = true; |
173 end | 175 end |
174 end | 176 end |
175 end | 177 if xmlfile then |
176 if xmlfile then | 178 xmlfile:close(); |
177 xmlfile:close(); | 179 xmlfile = nil; |
178 xmlfile = nil; | 180 end |
179 end | 181 end |
180 end | 182 end |
181 end | 183 end |
182 | 184 |
183 function archive:delete(username, query) | 185 function archive:delete(username, query) |