Comparison

plugins/mod_mam/mod_mam.lua @ 9758:d4a534e6bd7c

mod_mam: Handle expiry of messages that expire in the middle of the cut-off day
author Kim Alvefur <zash@zash.se>
date Sun, 06 Jan 2019 09:44:55 +0100
parent 9757:03ed7f10d8da
child 9802:d725c2ab0c7d
comparison
equal deleted inserted replaced
9757:03ed7f10d8da 9758:d4a534e6bd7c
356 cleanup_runner = require "util.async".runner(function () 356 cleanup_runner = require "util.async".runner(function ()
357 local cleanup_done = cleanup_time(); 357 local cleanup_done = cleanup_time();
358 local users = {}; 358 local users = {};
359 local cut_off = datestamp(os.time() - cleanup_after); 359 local cut_off = datestamp(os.time() - cleanup_after);
360 for date in cleanup_storage:users() do 360 for date in cleanup_storage:users() do
361 if date < cut_off then 361 if date <= cut_off then
362 module:log("debug", "Messages from %q should be expired", date); 362 module:log("debug", "Messages from %q should be expired", date);
363 local messages_this_day = cleanup_storage:get(date); 363 local messages_this_day = cleanup_storage:get(date);
364 if messages_this_day then 364 if messages_this_day then
365 for user in pairs(messages_this_day) do 365 for user in pairs(messages_this_day) do
366 users[user] = true; 366 users[user] = true;
367 end 367 end
368 cleanup_storage:set(date, nil); 368 if date < cut_off then
369 -- Messages from the same day as the cut-off might not have expired yet,
370 -- but all earlier will have, so clear storage for those days.
371 cleanup_storage:set(date, nil);
372 end
369 end 373 end
370 end 374 end
371 end 375 end
372 local sum, num_users = 0, 0; 376 local sum, num_users = 0, 0;
373 for user in pairs(users) do 377 for user in pairs(users) do