Comparison

plugins/mod_mam/mod_mam.lua @ 10800:62794e065e33

MAM: Remove 1% of contents when reaching limits, fix #1545 With mod\_storage\_internal this counts out to 100 messages out of 10 000, meaning should not hit the quota limit immediately until that many messages have been added again.
author Kim Alvefur <zash@zash.se>
date Tue, 05 May 2020 22:21:39 +0200
parent 10773:3e1046b39484
child 10821:30fc1ed5647a
comparison
equal deleted inserted replaced
10799:763bb2ce3f60 10800:62794e065e33
42 local archive = module:open_store(archive_store, "archive"); 42 local archive = module:open_store(archive_store, "archive");
43 43
44 local cleanup_after = module:get_option_string("archive_expires_after", "1w"); 44 local cleanup_after = module:get_option_string("archive_expires_after", "1w");
45 local cleanup_interval = module:get_option_number("archive_cleanup_interval", 4 * 60 * 60); 45 local cleanup_interval = module:get_option_number("archive_cleanup_interval", 4 * 60 * 60);
46 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000); 46 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000);
47 local archive_truncate = math.floor(archive_item_limit * 0.99);
48
47 if not archive.find then 49 if not archive.find then
48 error("mod_"..(archive._provided_by or archive.name and "storage_"..archive.name).." does not support archiving\n" 50 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"); 51 .."See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information");
50 end 52 end
51 local use_total = module:get_option_boolean("mam_include_total", true); 53 local use_total = module:get_option_boolean("mam_include_total", true);
377 end 379 end
378 end 380 end
379 if not ok and (archive.caps and archive.caps.truncate) then 381 if not ok and (archive.caps and archive.caps.truncate) then
380 module:log("debug", "User '%s' over quota, truncating archive", store_user); 382 module:log("debug", "User '%s' over quota, truncating archive", store_user);
381 local truncated = archive:delete(store_user, { 383 local truncated = archive:delete(store_user, {
382 truncate = archive_item_limit - 1; 384 truncate = archive_truncate;
383 }); 385 });
384 if truncated then 386 if truncated then
385 ok, err = archive:append(store_user, nil, clone_for_storage, time, with); 387 ok, err = archive:append(store_user, nil, clone_for_storage, time, with);
386 end 388 end
387 end 389 end