Software / code / prosody
Comparison
plugins/mod_mam/mod_mam.lua @ 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 |
| parent | 9886:710a116341cd |
| child | 10021:4715c5d1eb69 |
comparison
equal
deleted
inserted
replaced
| 9893:15270547c91c | 9894:8747ccf0008c |
|---|---|
| 300 | 300 |
| 301 -- And stash it | 301 -- And stash it |
| 302 local time = time_now(); | 302 local time = time_now(); |
| 303 local ok, err = archive:append(store_user, nil, clone_for_storage, time, with); | 303 local ok, err = archive:append(store_user, nil, clone_for_storage, time, with); |
| 304 if not ok and err == "quota-limit" then | 304 if not ok and err == "quota-limit" then |
| 305 if archive.caps and archive.caps.truncate then | 305 if type(cleanup_after) == "number" then |
| 306 module:log("debug", "User '%s' over quota, trimming archive", store_user); | 306 module:log("debug", "User '%s' over quota, cleaning archive", store_user); |
| 307 local cleaned = archive:delete(store_user, { | |
| 308 ["end"] = (os.time() - cleanup_after); | |
| 309 }); | |
| 310 if cleaned then | |
| 311 ok, err = archive:append(store_user, nil, clone_for_storage, time, with); | |
| 312 end | |
| 313 end | |
| 314 if not ok and (archive.caps and archive.caps.truncate) then | |
| 315 module:log("debug", "User '%s' over quota, truncating archive", store_user); | |
| 307 local truncated = archive:delete(store_user, { | 316 local truncated = archive:delete(store_user, { |
| 308 truncate = archive_item_limit - 1; | 317 truncate = archive_item_limit - 1; |
| 309 ["end"] = type(cleanup_after) == "number" and (os.time() - cleanup_after) or nil; | |
| 310 }); | 318 }); |
| 311 if truncated then | 319 if truncated then |
| 312 ok, err = archive:append(store_user, nil, clone_for_storage, time, with); | 320 ok, err = archive:append(store_user, nil, clone_for_storage, time, with); |
| 313 end | 321 end |
| 314 end | 322 end |