Comparison

mod_storage_xmlarchive/mod_storage_xmlarchive.lua @ 4649:62d41447615d

mod_storage_xmlarchive: Support query by list of IDs Needed for extended MAM
author Kim Alvefur <zash@zash.se>
date Sun, 15 Aug 2021 12:57:00 +0200
parent 4648:37ca6109077f
child 4671:98bf0f597df4
comparison
equal deleted inserted replaced
4648:37ca6109077f 4649:62d41447615d
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 full_id_range = true;
29 ids = true;
29 }; 30 };
30 31
31 local is_stanza = st.is_stanza or function (s) 32 local is_stanza = st.is_stanza or function (s)
32 return getmetatable(s) == st.stanza_mt; 33 return getmetatable(s) == st.stanza_mt;
33 end 34 end
201 stream_session.notopen = true; 202 stream_session.notopen = true;
202 stream:feed(st.stanza("stream", { xmlns = "jabber:client" }):top_tag()); 203 stream:feed(st.stanza("stream", { xmlns = "jabber:client" }):top_tag());
203 stream_session.notopen = nil; 204 stream_session.notopen = nil;
204 end 205 end
205 reset_stream(); 206 reset_stream();
207
208 local filtered_ids = false;
209 local filtered_dates = false;
210 if query.ids then
211 filtered_ids = {};
212 filtered_dates = {};
213 for _, id in ipairs(query.ids) do
214 filtered_ids[id] = true;
215 if filtered_dates then
216 local date = id:match("^%d%d%d%d%-%d%d%-%d%d");
217 if date then
218 filtered_dates[date] = true;
219 else
220 -- if any id diverges from the standard then the item could be from any date
221 filtered_dates = nil;
222 end
223 end
224 end
225 end
226
227 if filtered_dates then
228 for i = #dates, 1, -1 do
229 if not filtered_dates[ dates[i] ] then
230 table.remove(dates, i);
231 end
232 end
233 end
206 234
207 local limit = query.limit; 235 local limit = query.limit;
208 local start_day, step, last_day = 1, 1, #dates; 236 local start_day, step, last_day = 1, 1, #dates;
209 local count = 0; 237 local count = 0;
210 local rev = query.reverse; 238 local rev = query.reverse;
337 return; 365 return;
338 end 366 end
339 367
340 if (not q_with or i_with == q_with) 368 if (not q_with or i_with == q_with)
341 and (not q_start or i_when >= q_start) 369 and (not q_start or i_when >= q_start)
342 and (not q_end or i_when <= q_end) then 370 and (not q_end or i_when <= q_end)
371 and (not filtered_ids or filtered_ids[item.id]) then
343 count = count + 1; 372 count = count + 1;
344 first_item = i + step; 373 first_item = i + step;
345 374
346 local data = read_xml(date, item.offset, item.length); 375 local data = read_xml(date, item.offset, item.length);
347 if not data then return end 376 if not data then return end