comparison mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 4648:37ca6109077f

mod_storage_xmlarchive: Support full id range queries
author Kim Alvefur <zash@zash.se>
date Fri, 13 Aug 2021 01:23:34 +0200
parents b91e40472d68
children 62d41447615d
comparison
equal deleted inserted replaced
4647:b91e40472d68 4648:37ca6109077f
23 local archive_mt = { __index = archive }; 23 local archive_mt = { __index = archive };
24 24
25 archive.caps = { 25 archive.caps = {
26 total = false, 26 total = false,
27 quota = nil, 27 quota = nil,
28 full_id_range = true;
28 }; 29 };
29 30
30 local is_stanza = st.is_stanza or function (s) 31 local is_stanza = st.is_stanza or function (s)
31 return getmetatable(s) == st.stanza_mt; 32 return getmetatable(s) == st.stanza_mt;
32 end 33 end
227 end 228 end
228 end 229 end
229 end 230 end
230 local items; 231 local items;
231 local first_item, last_item; 232 local first_item, last_item;
233 local stop_at_id;
232 if rev then 234 if rev then
233 start_day, step, last_day = last_day, -step, start_day; 235 start_day, step, last_day = last_day, -step, start_day;
234 if query.before then 236 if query.before then
235 local before_day, before_item, items_ = self:_get_idx(username, query.before, dates); 237 local before_day, before_item, items_ = self:_get_idx(username, query.before, dates);
236 if not before_day then 238 if not before_day then
244 last_item = 1; 246 last_item = 1;
245 start_day = before_day; 247 start_day = before_day;
246 items = items_; 248 items = items_;
247 end 249 end
248 end 250 end
251 if query.after then
252 stop_at_id = query.after;
253 end
249 elseif query.after then 254 elseif query.after then
250 local after_day, after_item, items_ = self:_get_idx(username, query.after, dates); 255 local after_day, after_item, items_ = self:_get_idx(username, query.after, dates);
251 if not after_day then 256 if not after_day then
252 return nil, "item-not-found"; 257 return nil, "item-not-found";
253 elseif after_day >= start_day then 258 elseif after_day >= start_day then
258 end 263 end
259 last_item = #items_; 264 last_item = #items_;
260 start_day = after_day; 265 start_day = after_day;
261 items = items_; 266 items = items_;
262 end 267 end
268 if query.before then
269 stop_at_id = query.before;
270 end
271 elseif query.before then
272 stop_at_id = query.before;
263 end 273 end
264 274
265 local date_open, xmlfile; 275 local date_open, xmlfile;
266 local function read_xml(date, offset, length) 276 local function read_xml(date, offset, length)
267 if xmlfile and date ~= date_open then 277 if xmlfile and date ~= date_open then
318 i_when = dt.parse(i_when); 328 i_when = dt.parse(i_when);
319 end 329 end
320 if type(i_when) ~= "number" then 330 if type(i_when) ~= "number" then
321 module:log("warn", "data[%q][%d].when is invalid", date, i); 331 module:log("warn", "data[%q][%d].when is invalid", date, i);
322 break; 332 break;
333 end
334
335 if stop_at_id and stop_at_id == item.id then
336 if xmlfile then xmlfile:close(); end
337 return;
323 end 338 end
324 339
325 if (not q_with or i_with == q_with) 340 if (not q_with or i_with == q_with)
326 and (not q_start or i_when >= q_start) 341 and (not q_start or i_when >= q_start)
327 and (not q_end or i_when <= q_end) then 342 and (not q_end or i_when <= q_end) then