Comparison

plugins/mod_mam/mod_mam.lua @ 11968:6e1af07921d1

mod_mam,mod_muc_mam: Simplify deletion when multi-user-deletion is supported More code, but less of it needs to run and no extra tracking is needed.
author Kim Alvefur <zash@zash.se>
date Tue, 30 Nov 2021 01:22:14 +0100
parent 11875:210a785dfa8a
child 11988:18c0ca5fcbb8
comparison
equal deleted inserted replaced
11967:0f2b5182e80b 11968:6e1af07921d1
507 507
508 -- For each day, store a set of users that have new messages. To expire 508 -- For each day, store a set of users that have new messages. To expire
509 -- messages, we collect the union of sets of users from dates that fall 509 -- messages, we collect the union of sets of users from dates that fall
510 -- outside the cleanup range. 510 -- outside the cleanup range.
511 511
512 local last_date = require "util.cache".new(module:get_option_number("archive_cleanup_date_cache_size", 1000)); 512 if not (archive.caps and archive.caps.wildcard_delete) then
513 function schedule_cleanup(username, date) 513 local last_date = require "util.cache".new(module:get_option_number("archive_cleanup_date_cache_size", 1000));
514 date = date or datestamp(); 514 function schedule_cleanup(username, date)
515 if last_date:get(username) == date then return end 515 date = date or datestamp();
516 local ok = cleanup_map:set(date, username, true); 516 if last_date:get(username) == date then return end
517 if ok then 517 local ok = cleanup_map:set(date, username, true);
518 last_date:set(username, date); 518 if ok then
519 end 519 last_date:set(username, date);
520 end 520 end
521 end
522 end
523
521 local cleanup_time = module:measure("cleanup", "times"); 524 local cleanup_time = module:measure("cleanup", "times");
522 525
523 local async = require "util.async"; 526 local async = require "util.async";
524 cleanup_runner = async.runner(function () 527 cleanup_runner = async.runner(function ()
525 local cleanup_done = cleanup_time(); 528 local cleanup_done = cleanup_time();
529
530 if archive.caps and archive.caps.wildcard_delete then
531 local ok, err = archive:delete(true, { ["end"] = os.time() - cleanup_after })
532 if ok then
533 local sum = tonumber(ok);
534 if sum then
535 module:log("info", "Deleted %d expired messages", sum);
536 else
537 -- driver did not tell
538 module:log("info", "Deleted all expired messages");
539 end
540 else
541 module:log("error", "Could not delete messages: %s", err);
542 end
543 cleanup_done();
544 return;
545 end
546
526 local users = {}; 547 local users = {};
527 local cut_off = datestamp(os.time() - cleanup_after); 548 local cut_off = datestamp(os.time() - cleanup_after);
528 for date in cleanup_storage:users() do 549 for date in cleanup_storage:users() do
529 if date <= cut_off then 550 if date <= cut_off then
530 module:log("debug", "Messages from %q should be expired", date); 551 module:log("debug", "Messages from %q should be expired", date);