Software /
code /
prosody
Comparison
plugins/mod_muc_mam.lua @ 11989:871100cdbbad
mod_muc_mam: Switch to mod_cron for message expiry
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 22 Nov 2021 14:49:05 +0100 |
parent | 11968:6e1af07921d1 |
child | 12857:cc86d77481fc |
comparison
equal
deleted
inserted
replaced
11988:18c0ca5fcbb8 | 11989:871100cdbbad |
---|---|
33 local m_min = math.min; | 33 local m_min = math.min; |
34 local timestamp, datestamp = import("util.datetime", "datetime", "date"); | 34 local timestamp, datestamp = import("util.datetime", "datetime", "date"); |
35 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); | 35 local default_max_items, max_max_items = 20, module:get_option_number("max_archive_query_results", 50); |
36 | 36 |
37 local cleanup_after = module:get_option_string("muc_log_expires_after", "1w"); | 37 local cleanup_after = module:get_option_string("muc_log_expires_after", "1w"); |
38 local cleanup_interval = module:get_option_number("muc_log_cleanup_interval", 4 * 60 * 60); | |
39 | 38 |
40 local default_history_length = 20; | 39 local default_history_length = 20; |
41 local max_history_length = module:get_option_number("max_history_messages", math.huge); | 40 local max_history_length = module:get_option_number("max_history_messages", math.huge); |
42 | 41 |
43 local function get_historylength(room) | 42 local function get_historylength(room) |
492 end | 491 end |
493 | 492 |
494 local cleanup_time = module:measure("cleanup", "times"); | 493 local cleanup_time = module:measure("cleanup", "times"); |
495 | 494 |
496 local async = require "util.async"; | 495 local async = require "util.async"; |
497 cleanup_runner = async.runner(function () | 496 module:daily("Remove expired messages", function () |
498 local cleanup_done = cleanup_time(); | 497 local cleanup_done = cleanup_time(); |
499 | 498 |
500 if archive.caps and archive.caps.wildcard_delete then | 499 if archive.caps and archive.caps.wildcard_delete then |
501 local ok, err = archive:delete(true, { ["end"] = os.time() - cleanup_after }) | 500 local ok, err = archive:delete(true, { ["end"] = os.time() - cleanup_after }) |
502 if ok then | 501 if ok then |
548 end | 547 end |
549 module:log("info", "Deleted %d expired messages for %d rooms", sum, num_rooms); | 548 module:log("info", "Deleted %d expired messages for %d rooms", sum, num_rooms); |
550 cleanup_done(); | 549 cleanup_done(); |
551 end); | 550 end); |
552 | 551 |
553 cleanup_task = module:add_timer(1, function () | |
554 cleanup_runner:run(true); | |
555 return cleanup_interval; | |
556 end); | |
557 else | 552 else |
558 module:log("debug", "Archive expiry disabled"); | 553 module:log("debug", "Archive expiry disabled"); |
559 end | 554 end |