diff options
author | Kim Alvefur <zash@zash.se> | 2019-03-22 02:22:21 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2019-03-22 02:22:21 +0100 |
commit | 36900805270064f089c7e3ae9b2e3be6b7a63df0 (patch) | |
tree | 718bcaa9fc9dfced3c8f81e16e65214e1ea65644 /plugins/mod_mam | |
parent | 2a073294ae4a6eccc10ffcef2a2146bfb9abe1ae (diff) | |
download | prosody-36900805270064f089c7e3ae9b2e3be6b7a63df0.tar.gz prosody-36900805270064f089c7e3ae9b2e3be6b7a63df0.zip |
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.
Diffstat (limited to 'plugins/mod_mam')
-rw-r--r-- | plugins/mod_mam/mod_mam.lua | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 5be4bc24..632de9ea 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -302,11 +302,19 @@ local function message_handler(event, c2s) 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); |