Comparison

plugins/mod_muc_mam.lua @ 10029:2c8f674b9243 0.11

mod_muc_mam: Cache last date that archive owner has messages to reduce writes (fixes #1368)
author Kim Alvefur <zash@zash.se>
date Mon, 27 May 2019 19:00:34 +0200
parent 9880:78885b1bbb91
child 10030:98ef41a60fc3
child 10526:28c8e09fb3cd
comparison
equal deleted inserted replaced
10028:79ba2d709e72 10029:2c8f674b9243
420 420
421 -- For each day, store a set of rooms that have new messages. To expire 421 -- For each day, store a set of rooms that have new messages. To expire
422 -- messages, we collect the union of sets of rooms from dates that fall 422 -- messages, we collect the union of sets of rooms from dates that fall
423 -- outside the cleanup range. 423 -- outside the cleanup range.
424 424
425 local last_date = require "util.cache".new(module:get_option_number("muc_log_cleanup_date_cache_size", 1000));
425 function schedule_cleanup(roomname, date) 426 function schedule_cleanup(roomname, date)
426 cleanup_map:set(date or datestamp(), roomname, true); 427 date = date or datestamp();
428 if last_date:get(roomname) == date then return end
429 local ok = cleanup_map:set(date, roomname, true);
430 if ok then
431 last_date:set(roomname, date);
432 end
427 end 433 end
428 434
429 cleanup_runner = require "util.async".runner(function () 435 cleanup_runner = require "util.async".runner(function ()
430 local rooms = {}; 436 local rooms = {};
431 local cut_off = datestamp(os.time() - cleanup_after); 437 local cut_off = datestamp(os.time() - cleanup_after);