# HG changeset patch # User Kim Alvefur # Date 1553217741 -3600 # Node ID 8747ccf0008c6c9fb7f3b839357e72afc19d20b2 # Parent 15270547c91c9a0ec36f92feba3f905e36ffce7c 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. diff -r 15270547c91c -r 8747ccf0008c plugins/mod_mam/mod_mam.lua --- 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);