Comparison

plugins/mod_mam/mod_mam.lua @ 10030:98ef41a60fc3

Merge 0.11->trunk
author Kim Alvefur <zash@zash.se>
date Mon, 27 May 2019 19:17:12 +0200
parent 10021:4715c5d1eb69
parent 10028:79ba2d709e72
child 10071:b36e2631203d
comparison
equal deleted inserted replaced
10027:c0ee2ed8ef19 10030:98ef41a60fc3
41 local archive = module:open_store(archive_store, "archive"); 41 local archive = module:open_store(archive_store, "archive");
42 42
43 local cleanup_after = module:get_option_string("archive_expires_after", "1w"); 43 local cleanup_after = module:get_option_string("archive_expires_after", "1w");
44 local cleanup_interval = module:get_option_number("archive_cleanup_interval", 4 * 60 * 60); 44 local cleanup_interval = module:get_option_number("archive_cleanup_interval", 4 * 60 * 60);
45 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000); 45 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000);
46
47 if not archive.find then 46 if not archive.find then
48 error("mod_"..(archive._provided_by or archive.name and "storage_"..archive.name).." does not support archiving\n" 47 error("mod_"..(archive._provided_by or archive.name and "storage_"..archive.name).." does not support archiving\n"
49 .."See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information"); 48 .."See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information");
50 end 49 end
51 local use_total = module:get_option_boolean("mam_include_total", true); 50 local use_total = module:get_option_boolean("mam_include_total", true);
373 372
374 -- For each day, store a set of users that have new messages. To expire 373 -- For each day, store a set of users that have new messages. To expire
375 -- messages, we collect the union of sets of users from dates that fall 374 -- messages, we collect the union of sets of users from dates that fall
376 -- outside the cleanup range. 375 -- outside the cleanup range.
377 376
377 local last_date = require "util.cache".new(module:get_option_number("archive_cleanup_date_cache_size", 1000));
378 function schedule_cleanup(username, date) 378 function schedule_cleanup(username, date)
379 cleanup_map:set(date or datestamp(), username, true); 379 date = date or datestamp();
380 end 380 if last_date:get(username) == date then return end
381 local ok = cleanup_map:set(date, username, true);
382 if ok then
383 last_date:set(username, date);
384 end
385 end
381 local cleanup_time = module:measure("cleanup", "times"); 386 local cleanup_time = module:measure("cleanup", "times");
382 387
383 cleanup_runner = require "util.async".runner(function () 388 cleanup_runner = require "util.async".runner(function ()
384 local cleanup_done = cleanup_time(); 389 local cleanup_done = cleanup_time();
385 local users = {}; 390 local users = {};