comparison mod_storage_s3/mod_storage_s3.lua @ 5733:b6518a71ca7e

mod_storage_s3: Implement search for set of IDs This together with the full id range query enables support for urn:xmpp:mam:2#extended in mod_mam
author Kim Alvefur <zash@zash.se>
date Sun, 26 Nov 2023 22:44:01 +0100
parents e8938a3166d2
children 9a1d8c39d0b0
comparison
equal deleted inserted replaced
5732:e8938a3166d2 5733:b6518a71ca7e
6 local httputil = require "prosody.util.http"; 6 local httputil = require "prosody.util.http";
7 local it = require "prosody.util.iterators"; 7 local it = require "prosody.util.iterators";
8 local jid = require "prosody.util.jid"; 8 local jid = require "prosody.util.jid";
9 local json = require "prosody.util.json"; 9 local json = require "prosody.util.json";
10 local promise = require "prosody.util.promise"; 10 local promise = require "prosody.util.promise";
11 local set = require "prosody.util.set";
11 local st = require "prosody.util.stanza"; 12 local st = require "prosody.util.stanza";
12 local uuid = require "prosody.util.uuid"; 13 local uuid = require "prosody.util.uuid";
13 local xml = require "prosody.util.xml"; 14 local xml = require "prosody.util.xml";
14 local url = require "socket.url"; 15 local url = require "socket.url";
15 16
197 local archive = {}; 198 local archive = {};
198 driver.archive = { __index = archive }; 199 driver.archive = { __index = archive };
199 200
200 archive.caps = { 201 archive.caps = {
201 full_id_range = true; -- both before and after used 202 full_id_range = true; -- both before and after used
203 ids = true;
202 }; 204 };
203 205
204 function archive:_path(username, date, when, with, key) 206 function archive:_path(username, date, when, with, key)
205 return url.build_path({ 207 return url.build_path({
206 is_absolute = true; 208 is_absolute = true;
264 end 266 end
265 if query["reverse"] then 267 if query["reverse"] then
266 query["before"], query["after"] = query["after"], query["before"]; 268 query["before"], query["after"] = query["after"], query["before"];
267 iterwrap = it.reverse; 269 iterwrap = it.reverse;
268 end 270 end
271 local ids = query["ids"] and set.new(query["ids"]);
269 local found = not query["after"]; 272 local found = not query["after"];
270 for content in iterwrap(list_bucket_result:childtags("Contents")) do 273 for content in iterwrap(list_bucket_result:childtags("Contents")) do
271 local key = url.parse_path(content:get_child_text("Key")); 274 local key = url.parse_path(content:get_child_text("Key"));
272 if found and query["before"] == key[6] then 275 if found and query["before"] == key[6] then
273 break 276 break
274 end 277 end
275 if (not query["with"] or query["with"] == jid.unescape(key[5])) 278 if (not query["with"] or query["with"] == jid.unescape(key[5]))
276 and (not query["start"] or dt.date(query["start"]) >= key[6]) 279 and (not query["start"] or dt.date(query["start"]) >= key[6])
277 and (not query["end"] or dt.date(query["end"]) <= key[6]) 280 and (not query["end"] or dt.date(query["end"]) <= key[6])
281 and (not ids or ids:contains(key[6]))
278 and found then 282 and found then
279 keys:push({ key = key[6]; date = key[5]; with = jid.unescape(key[4]) }); 283 keys:push({ key = key[6]; date = key[5]; with = jid.unescape(key[4]) });
280 end 284 end
281 if not found and key[6] == query["after"] then 285 if not found and key[6] == query["after"] then
282 found = not found 286 found = not found