Software /
code /
prosody-modules
Comparison
mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 2633:1330ed88ecd8
mod_storage_xmlarchive: Cache current date in a local
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 21 Mar 2017 11:17:17 +0100 |
parent | 2632:995d4d9f5d89 |
child | 2634:71ce798c86cc |
comparison
equal
deleted
inserted
replaced
2632:995d4d9f5d89 | 2633:1330ed88ecd8 |
---|---|
175 end | 175 end |
176 | 176 |
177 return function () | 177 return function () |
178 if limit and count >= limit then if xmlfile then xmlfile:close() end return; end | 178 if limit and count >= limit then if xmlfile then xmlfile:close() end return; end |
179 for d = start_day, last_day, step do | 179 for d = start_day, last_day, step do |
180 local date = dates[d]; | |
180 if not items then | 181 if not items then |
181 module:log("debug", "Loading items from %s", dates[d]); | 182 module:log("debug", "Loading items from %s", date); |
182 start_day = d; | 183 start_day = d; |
183 items = dm.list_load(username .. "@" .. dates[d], module.host, self.store) or empty; | 184 items = dm.list_load(username .. "@" .. date, module.host, self.store) or empty; |
184 if not rev then | 185 if not rev then |
185 first_item, last_item = 1, #items; | 186 first_item, last_item = 1, #items; |
186 else | 187 else |
187 first_item, last_item = #items, 1; | 188 first_item, last_item = #items, 1; |
188 end | 189 end |
190 | 191 |
191 local q_with, q_start, q_end = query.with, query.start, query["end"]; | 192 local q_with, q_start, q_end = query.with, query.start, query["end"]; |
192 for i = first_item, last_item, step do | 193 for i = first_item, last_item, step do |
193 local item = items[i]; | 194 local item = items[i]; |
194 if not item then | 195 if not item then |
195 module:log("warn", "data[%q][%d] is nil", dates[d], i); | 196 module:log("warn", "data[%q][%d] is nil", date, i); |
196 break; | 197 break; |
197 end | 198 end |
198 local i_when, i_with = item.when, item.with; | 199 local i_when, i_with = item.when, item.with; |
199 if type(i_when) == "string" then | 200 if type(i_when) == "string" then |
200 i_when = dt.parse(i_when); | 201 i_when = dt.parse(i_when); |
201 end | 202 end |
202 if type(i_when) ~= "number" then | 203 if type(i_when) ~= "number" then |
203 module:log("warn", "data[%q][%d].when is invalid", dates[d], i); | 204 module:log("warn", "data[%q][%d].when is invalid", date, i); |
204 break; | 205 break; |
205 end | 206 end |
206 if (not q_with or i_with == q_with) | 207 if (not q_with or i_with == q_with) |
207 and (not q_start or i_when >= q_start) | 208 and (not q_start or i_when >= q_start) |
208 and (not q_end or i_when <= q_end) then | 209 and (not q_end or i_when <= q_end) then |
209 count = count + 1; | 210 count = count + 1; |
210 first_item = i + step; | 211 first_item = i + step; |
211 | 212 |
212 local data = read_xml(dates[d], item.offset, item.length); | 213 local data = read_xml(date, item.offset, item.length); |
213 if not data then return end | 214 if not data then return end |
214 local ok, err = stream:feed(data); | 215 local ok, err = stream:feed(data); |
215 if not ok then | 216 if not ok then |
216 module:log("warn", "Parse error in %s@%s/%s/%q[%d]: %s", username, module.host, self.store, i, err); | 217 module:log("warn", "Parse error in %s@%s/%s/%q[%d]: %s", username, module.host, self.store, i, err); |
217 reset_stream(); | 218 reset_stream(); |