mod_storage_s3: Skip archive items matching on date but not full datetime
authorKim Alvefur <zash@zash.se>
Sat, 11 Nov 2023 22:26:39 +0100
changeset 5700 66986f5271c3
parent 5699 b4632d5f840b
child 5701 4a0279c5c7ed
mod_storage_s3: Skip archive items matching on date but not full datetime Since it only encodes dates in paths, it would have returned items from outside the specified start..end range if they were from earlier or later in the same (UTC) day.
mod_storage_s3/mod_storage_s3.lua
--- a/mod_storage_s3/mod_storage_s3.lua	Sat Nov 11 17:01:29 2023 +0100
+++ b/mod_storage_s3/mod_storage_s3.lua	Sat Nov 11 22:26:39 2023 +0100
@@ -281,7 +281,7 @@
 		end
 	end
 	local i = 0;
-	return function()
+	local function get_next()
 		i = i + 1;
 		local item = keys[i];
 		if item == nil then
@@ -293,10 +293,16 @@
 			module:log("error", "%s", err);
 			return nil;
 		end
-		local delay = value:get_child("delay", "urn:xmpp:delay");
+		local when = dt.parse(value:get_child_attr("delay", "urn:xmpp:delay", "stamp"));
 
-		return item.key, value.tags[2], dt.parse(delay.attr.stamp), item.with;
+		if (not query["start"] or query["start"] >= when) and (not query["end"] or query["end"] <= when) then
+			return item.key, value.tags[2], when, item.with;
+		else
+			-- date was correct but not the time
+			return get_next();
+		end
 	end
+	return get_next;
 end
 
 function archive:users()