Changeset

9894:8747ccf0008c

mod_mam: On quota hit, separately delete by time and by item count This is to work around a possible SQL issue where offsets and time stamps don't interact correctly.
author Kim Alvefur <zash@zash.se>
date Fri, 22 Mar 2019 02:22:21 +0100
parents 9893:15270547c91c
children 9895:6bd65bff03b5
files plugins/mod_mam/mod_mam.lua
diffstat 1 files changed, 11 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_mam/mod_mam.lua	Fri Mar 22 02:18:54 2019 +0100
+++ b/plugins/mod_mam/mod_mam.lua	Fri Mar 22 02:22:21 2019 +0100
@@ -302,11 +302,19 @@
 		local time = time_now();
 		local ok, err = archive:append(store_user, nil, clone_for_storage, time, with);
 		if not ok and err == "quota-limit" then
-			if archive.caps and archive.caps.truncate then
-				module:log("debug", "User '%s' over quota, trimming archive", store_user);
+			if type(cleanup_after) == "number" then
+				module:log("debug", "User '%s' over quota, cleaning archive", store_user);
+				local cleaned = archive:delete(store_user, {
+					["end"] = (os.time() - cleanup_after);
+				});
+				if cleaned then
+					ok, err = archive:append(store_user, nil, clone_for_storage, time, with);
+				end
+			end
+			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;
-					["end"] = type(cleanup_after) == "number" and (os.time() - cleanup_after) or nil;
 				});
 				if truncated then
 					ok, err = archive:append(store_user, nil, clone_for_storage, time, with);