mod_mam: Handle expiry of messages that expire in the middle of the cut-off day
authorKim Alvefur <zash@zash.se>
Sun, 06 Jan 2019 09:44:55 +0100
changeset 9762 d4a534e6bd7c
parent 9761 03ed7f10d8da
child 9763 1af5106a2c34
mod_mam: Handle expiry of messages that expire in the middle of the cut-off day
plugins/mod_mam/mod_mam.lua
--- a/plugins/mod_mam/mod_mam.lua	Sun Jan 06 09:34:59 2019 +0100
+++ b/plugins/mod_mam/mod_mam.lua	Sun Jan 06 09:44:55 2019 +0100
@@ -358,14 +358,18 @@
 		local users = {};
 		local cut_off = datestamp(os.time() - cleanup_after);
 		for date in cleanup_storage:users() do
-			if date < cut_off then
+			if date <= cut_off then
 				module:log("debug", "Messages from %q should be expired", date);
 				local messages_this_day = cleanup_storage:get(date);
 				if messages_this_day then
 					for user in pairs(messages_this_day) do
 						users[user] = true;
 					end
-					cleanup_storage:set(date, nil);
+					if date < cut_off then
+						-- Messages from the same day as the cut-off might not have expired yet,
+						-- but all earlier will have, so clear storage for those days.
+						cleanup_storage:set(date, nil);
+					end
 				end
 			end
 		end