# HG changeset patch # User Kim Alvefur # Date 1629025020 -7200 # Node ID 62d41447615d6648ea1907c064841ba53fe7d959 # Parent 37ca6109077f7288d74fbee00b239d0f2ad9e22c mod_storage_xmlarchive: Support query by list of IDs Needed for extended MAM diff -r 37ca6109077f -r 62d41447615d mod_storage_xmlarchive/mod_storage_xmlarchive.lua --- a/mod_storage_xmlarchive/mod_storage_xmlarchive.lua Fri Aug 13 01:23:34 2021 +0200 +++ b/mod_storage_xmlarchive/mod_storage_xmlarchive.lua Sun Aug 15 12:57:00 2021 +0200 @@ -26,6 +26,7 @@ total = false, quota = nil, full_id_range = true; + ids = true; }; local is_stanza = st.is_stanza or function (s) @@ -204,6 +205,33 @@ end reset_stream(); + local filtered_ids = false; + local filtered_dates = false; + if query.ids then + filtered_ids = {}; + filtered_dates = {}; + for _, id in ipairs(query.ids) do + filtered_ids[id] = true; + if filtered_dates then + local date = id:match("^%d%d%d%d%-%d%d%-%d%d"); + if date then + filtered_dates[date] = true; + else + -- if any id diverges from the standard then the item could be from any date + filtered_dates = nil; + end + end + end + end + + if filtered_dates then + for i = #dates, 1, -1 do + if not filtered_dates[ dates[i] ] then + table.remove(dates, i); + end + end + end + local limit = query.limit; local start_day, step, last_day = 1, 1, #dates; local count = 0; @@ -339,7 +367,8 @@ if (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 + and (not q_end or i_when <= q_end) + and (not filtered_ids or filtered_ids[item.id]) then count = count + 1; first_item = i + step;