Changeset

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
parents 10799:763bb2ce3f60
children 10801:2b97aac0ea3c
files plugins/mod_mam/mod_mam.lua plugins/mod_muc_mam.lua
diffstat 2 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_mam/mod_mam.lua	Mon May 04 21:51:30 2020 +0200
+++ b/plugins/mod_mam/mod_mam.lua	Tue May 05 22:21:39 2020 +0200
@@ -44,6 +44,8 @@
 local cleanup_after = module:get_option_string("archive_expires_after", "1w");
 local cleanup_interval = module:get_option_number("archive_cleanup_interval", 4 * 60 * 60);
 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000);
+local archive_truncate = math.floor(archive_item_limit * 0.99);
+
 if not archive.find then
 	error("mod_"..(archive._provided_by or archive.name and "storage_"..archive.name).." does not support archiving\n"
 		.."See https://prosody.im/doc/storage and https://prosody.im/doc/archiving for more information");
@@ -379,7 +381,7 @@
 			if not ok and (archive.caps and archive.caps.truncate) then
 				module:log("debug", "User '%s' over quota, truncating archive", store_user);
 				local truncated = archive:delete(store_user, {
-					truncate = archive_item_limit - 1;
+					truncate = archive_truncate;
 				});
 				if truncated then
 					ok, err = archive:append(store_user, nil, clone_for_storage, time, with);
--- a/plugins/mod_muc_mam.lua	Mon May 04 21:51:30 2020 +0200
+++ b/plugins/mod_muc_mam.lua	Tue May 05 22:21:39 2020 +0200
@@ -54,6 +54,7 @@
 local archive = module:open_store(archive_store, "archive");
 
 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000);
+local archive_truncate = math.floor(archive_item_limit * 0.99);
 
 if archive.name == "null" or not archive.find then
 	if not archive.find then
@@ -397,7 +398,7 @@
 		if not id and (archive.caps and archive.caps.truncate) then
 			module:log("debug", "User '%s' over quota, truncating archive", room_node);
 			local truncated = archive:delete(room_node, {
-				truncate = archive_item_limit - 1;
+				truncate = archive_truncate;
 			});
 			if truncated then
 				id, err = archive:append(room_node, nil, stored_stanza, time, with);