Software /
code /
prosody
Changeset
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 |
parents | 11967:0f2b5182e80b |
children | 11969:395dce95508d |
files | plugins/mod_mam/mod_mam.lua plugins/mod_muc_mam.lua |
diffstat | 2 files changed, 54 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/mod_mam/mod_mam.lua Tue Nov 30 01:21:02 2021 +0100 +++ b/plugins/mod_mam/mod_mam.lua Tue Nov 30 01:22:14 2021 +0100 @@ -509,20 +509,41 @@ -- messages, we collect the union of sets of users from dates that fall -- outside the cleanup range. - local last_date = require "util.cache".new(module:get_option_number("archive_cleanup_date_cache_size", 1000)); - function schedule_cleanup(username, date) - date = date or datestamp(); - if last_date:get(username) == date then return end - local ok = cleanup_map:set(date, username, true); - if ok then - last_date:set(username, date); + if not (archive.caps and archive.caps.wildcard_delete) then + local last_date = require "util.cache".new(module:get_option_number("archive_cleanup_date_cache_size", 1000)); + function schedule_cleanup(username, date) + date = date or datestamp(); + if last_date:get(username) == date then return end + local ok = cleanup_map:set(date, username, true); + if ok then + last_date:set(username, date); + end end end + local cleanup_time = module:measure("cleanup", "times"); local async = require "util.async"; cleanup_runner = async.runner(function () local cleanup_done = cleanup_time(); + + if archive.caps and archive.caps.wildcard_delete then + local ok, err = archive:delete(true, { ["end"] = os.time() - cleanup_after }) + if ok then + local sum = tonumber(ok); + if sum then + module:log("info", "Deleted %d expired messages", sum); + else + -- driver did not tell + module:log("info", "Deleted all expired messages"); + end + else + module:log("error", "Could not delete messages: %s", err); + end + cleanup_done(); + return; + end + local users = {}; local cut_off = datestamp(os.time() - cleanup_after); for date in cleanup_storage:users() do
--- a/plugins/mod_muc_mam.lua Tue Nov 30 01:21:02 2021 +0100 +++ b/plugins/mod_muc_mam.lua Tue Nov 30 01:22:14 2021 +0100 @@ -480,12 +480,14 @@ -- outside the cleanup range. local last_date = require "util.cache".new(module:get_option_number("muc_log_cleanup_date_cache_size", 1000)); - function schedule_cleanup(roomname, date) - date = date or datestamp(); - if last_date:get(roomname) == date then return end - local ok = cleanup_map:set(date, roomname, true); - if ok then - last_date:set(roomname, date); + if not ( archive.caps and archive.caps.wildcard_delete ) then + function schedule_cleanup(roomname, date) + date = date or datestamp(); + if last_date:get(roomname) == date then return end + local ok = cleanup_map:set(date, roomname, true); + if ok then + last_date:set(roomname, date); + end end end @@ -494,6 +496,24 @@ local async = require "util.async"; cleanup_runner = async.runner(function () local cleanup_done = cleanup_time(); + + if archive.caps and archive.caps.wildcard_delete then + local ok, err = archive:delete(true, { ["end"] = os.time() - cleanup_after }) + if ok then + local sum = tonumber(ok); + if sum then + module:log("info", "Deleted %d expired messages", sum); + else + -- driver did not tell + module:log("info", "Deleted all expired messages"); + end + else + module:log("error", "Could not delete messages: %s", err); + end + cleanup_done(); + return; + end + local rooms = {}; local cut_off = datestamp(os.time() - cleanup_after); for date in cleanup_storage:users() do