aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_mam
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-11-30 01:22:14 +0100
committerKim Alvefur <zash@zash.se>2021-11-30 01:22:14 +0100
commit59258d47bd246ad55de5accf4331f44933a9755d (patch)
tree07a1d79d2245c2a5a40b2cf080496ad77f0389d2 /plugins/mod_mam
parent0a50cf1be43fc088c5a115d3f32bc4f9b8c0b2e8 (diff)
downloadprosody-59258d47bd246ad55de5accf4331f44933a9755d.tar.gz
prosody-59258d47bd246ad55de5accf4331f44933a9755d.zip
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.
Diffstat (limited to 'plugins/mod_mam')
-rw-r--r--plugins/mod_mam/mod_mam.lua35
1 files changed, 28 insertions, 7 deletions
diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua
index facf5bc0..e418d60d 100644
--- a/plugins/mod_mam/mod_mam.lua
+++ b/plugins/mod_mam/mod_mam.lua
@@ -509,20 +509,41 @@ if cleanup_after ~= "never" then
-- 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