Comparison

plugins/mod_mam/mod_mam.lua @ 10028:79ba2d709e72 0.11

mod_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:32 +0200
parent 9879:ddc07fb8dcd4
child 10030:98ef41a60fc3
child 10298:906ea5e1ec75
comparison
equal deleted inserted replaced
10026:1117138fa372 10028:79ba2d709e72
346 346
347 -- For each day, store a set of users that have new messages. To expire 347 -- For each day, store a set of users that have new messages. To expire
348 -- messages, we collect the union of sets of users from dates that fall 348 -- messages, we collect the union of sets of users from dates that fall
349 -- outside the cleanup range. 349 -- outside the cleanup range.
350 350
351 local last_date = require "util.cache".new(module:get_option_number("archive_cleanup_date_cache_size", 1000));
351 function schedule_cleanup(username, date) 352 function schedule_cleanup(username, date)
352 cleanup_map:set(date or datestamp(), username, true); 353 date = date or datestamp();
354 if last_date:get(username) == date then return end
355 local ok = cleanup_map:set(date, username, true);
356 if ok then
357 last_date:set(username, date);
358 end
353 end 359 end
354 360
355 cleanup_runner = require "util.async".runner(function () 361 cleanup_runner = require "util.async".runner(function ()
356 local users = {}; 362 local users = {};
357 local cut_off = datestamp(os.time() - cleanup_after); 363 local cut_off = datestamp(os.time() - cleanup_after);