Software /
code /
prosody-modules
Comparison
mod_storage_s3/mod_storage_s3.lua @ 5760:72b0fa7e36dc
mod_storage_s3: Sort archive items by LastModified
Otherwise they would get sorted by who knows what, probably the path.
Also not sure if the timestamp comparisons were correct before.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 27 Nov 2023 14:27:35 +0100 |
parent | 5759:ba731ff5b895 |
child | 5781:32bc648e3892 |
comparison
equal
deleted
inserted
replaced
5759:ba731ff5b895 | 5760:72b0fa7e36dc |
---|---|
272 iterwrap = it.reverse; | 272 iterwrap = it.reverse; |
273 end | 273 end |
274 local ids = query["ids"] and set.new(query["ids"]); | 274 local ids = query["ids"] and set.new(query["ids"]); |
275 local found = not query["after"]; | 275 local found = not query["after"]; |
276 for content in iterwrap(list_bucket_result:childtags("Contents")) do | 276 for content in iterwrap(list_bucket_result:childtags("Contents")) do |
277 local when, with, id = table.unpack(url.parse_path(content:get_child_text("Key")), 4); | 277 local date, with, id = table.unpack(url.parse_path(content:get_child_text("Key")), 4); |
278 local when = dt.parse(content:get_child_text("LastModified")); | |
278 with = jid.unescape(with); | 279 with = jid.unescape(with); |
279 if found and query["before"] == id then | 280 if found and query["before"] == id then |
280 break | 281 break |
281 end | 282 end |
282 if (not query["with"] or query["with"] == with) | 283 if (not query["with"] or query["with"] == with) |
283 and (not query["start"] or dt.date(query["start"]) >= when) | 284 and (not query["start"] or query["start"] <= when) |
284 and (not query["end"] or dt.date(query["end"]) <= when) | 285 and (not query["end"] or query["end"] >= when) |
285 and (not ids or ids:contains(id)) | 286 and (not ids or ids:contains(id)) |
286 and found then | 287 and found then |
287 keys:push({ key = id; date = when; with = with }); | 288 keys:push({ key = id; date = date; when = when; with = with }); |
288 end | 289 end |
289 if not found and id == query["after"] then | 290 if not found and id == query["after"] then |
290 found = not found | 291 found = not found |
291 end | 292 end |
293 end | |
294 keys:sort(function(a, b) | |
295 if a.date ~= b.date then | |
296 return a.date < b.date | |
297 end | |
298 if a.when ~= b.when then | |
299 return a.when < b.when; | |
300 end | |
301 return a.id < b.id; | |
302 end); | |
303 if query["reverse"] then | |
304 keys:reverse(); | |
292 end | 305 end |
293 local i = 0; | 306 local i = 0; |
294 local function get_next() | 307 local function get_next() |
295 i = i + 1; | 308 i = i + 1; |
296 local item = keys[i]; | 309 local item = keys[i]; |
301 local value, err = async.wait_for(new_request(self, "GET", self:_path(username or "@", item.date, nil, item.with, item.key)):next(on_result)); | 314 local value, err = async.wait_for(new_request(self, "GET", self:_path(username or "@", item.date, nil, item.with, item.key)):next(on_result)); |
302 if not value then | 315 if not value then |
303 module:log("error", "%s", err); | 316 module:log("error", "%s", err); |
304 return nil; | 317 return nil; |
305 end | 318 end |
306 local when = dt.parse(value:get_child_attr("delay", "urn:xmpp:delay", "stamp")); | 319 return item.key, value, item.when, item.with; |
307 | |
308 if (not query["start"] or query["start"] >= when) and (not query["end"] or query["end"] <= when) then | |
309 return item.key, value.tags[2], when, item.with; | |
310 else | |
311 -- date was correct but not the time | |
312 return get_next(); | |
313 end | |
314 end | 320 end |
315 return get_next; | 321 return get_next; |
316 end | 322 end |
317 | 323 |
318 function archive:users() | 324 function archive:users() |