# HG changeset patch # User Kim Alvefur # Date 1558976432 -7200 # Node ID 79ba2d709e7276c2a63456936be6a86cf03e83f3 # Parent 1117138fa37285419354eb6cd9028dea04cab026 mod_mam: Cache last date that archive owner has messages to reduce writes (fixes #1368) diff -r 1117138fa372 -r 79ba2d709e72 plugins/mod_mam/mod_mam.lua --- a/plugins/mod_mam/mod_mam.lua Mon May 27 12:05:35 2019 +0200 +++ b/plugins/mod_mam/mod_mam.lua Mon May 27 19:00:32 2019 +0200 @@ -348,8 +348,14 @@ -- 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) - cleanup_map:set(date or datestamp(), username, true); + 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 cleanup_runner = require "util.async".runner(function ()