Software /
code /
prosody
Comparison
plugins/mod_muc_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 | 11876:52a1b885044e |
child | 11989:871100cdbbad |
comparison
equal
deleted
inserted
replaced
11967:0f2b5182e80b | 11968:6e1af07921d1 |
---|---|
478 -- For each day, store a set of rooms that have new messages. To expire | 478 -- For each day, store a set of rooms that have new messages. To expire |
479 -- messages, we collect the union of sets of rooms from dates that fall | 479 -- messages, we collect the union of sets of rooms from dates that fall |
480 -- outside the cleanup range. | 480 -- outside the cleanup range. |
481 | 481 |
482 local last_date = require "util.cache".new(module:get_option_number("muc_log_cleanup_date_cache_size", 1000)); | 482 local last_date = require "util.cache".new(module:get_option_number("muc_log_cleanup_date_cache_size", 1000)); |
483 function schedule_cleanup(roomname, date) | 483 if not ( archive.caps and archive.caps.wildcard_delete ) then |
484 date = date or datestamp(); | 484 function schedule_cleanup(roomname, date) |
485 if last_date:get(roomname) == date then return end | 485 date = date or datestamp(); |
486 local ok = cleanup_map:set(date, roomname, true); | 486 if last_date:get(roomname) == date then return end |
487 if ok then | 487 local ok = cleanup_map:set(date, roomname, true); |
488 last_date:set(roomname, date); | 488 if ok then |
489 last_date:set(roomname, date); | |
490 end | |
489 end | 491 end |
490 end | 492 end |
491 | 493 |
492 local cleanup_time = module:measure("cleanup", "times"); | 494 local cleanup_time = module:measure("cleanup", "times"); |
493 | 495 |
494 local async = require "util.async"; | 496 local async = require "util.async"; |
495 cleanup_runner = async.runner(function () | 497 cleanup_runner = async.runner(function () |
496 local cleanup_done = cleanup_time(); | 498 local cleanup_done = cleanup_time(); |
499 | |
500 if archive.caps and archive.caps.wildcard_delete then | |
501 local ok, err = archive:delete(true, { ["end"] = os.time() - cleanup_after }) | |
502 if ok then | |
503 local sum = tonumber(ok); | |
504 if sum then | |
505 module:log("info", "Deleted %d expired messages", sum); | |
506 else | |
507 -- driver did not tell | |
508 module:log("info", "Deleted all expired messages"); | |
509 end | |
510 else | |
511 module:log("error", "Could not delete messages: %s", err); | |
512 end | |
513 cleanup_done(); | |
514 return; | |
515 end | |
516 | |
497 local rooms = {}; | 517 local rooms = {}; |
498 local cut_off = datestamp(os.time() - cleanup_after); | 518 local cut_off = datestamp(os.time() - cleanup_after); |
499 for date in cleanup_storage:users() do | 519 for date in cleanup_storage:users() do |
500 if date <= cut_off then | 520 if date <= cut_off then |
501 module:log("debug", "Messages from %q should be expired", date); | 521 module:log("debug", "Messages from %q should be expired", date); |