Software /
code /
prosody
Comparison
plugins/mod_muc_mam.lua @ 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 |
parent | 10683:2f0b7f1d5e75 |
child | 10817:7c503938ce1d |
comparison
equal
deleted
inserted
replaced
10799:763bb2ce3f60 | 10800:62794e065e33 |
---|---|
52 | 52 |
53 local archive_store = "muc_log"; | 53 local archive_store = "muc_log"; |
54 local archive = module:open_store(archive_store, "archive"); | 54 local archive = module:open_store(archive_store, "archive"); |
55 | 55 |
56 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000); | 56 local archive_item_limit = module:get_option_number("storage_archive_item_limit", archive.caps and archive.caps.quota or 1000); |
57 local archive_truncate = math.floor(archive_item_limit * 0.99); | |
57 | 58 |
58 if archive.name == "null" or not archive.find then | 59 if archive.name == "null" or not archive.find then |
59 if not archive.find then | 60 if not archive.find then |
60 module:log("error", "Attempt to open archive storage returned a driver without archive API support"); | 61 module:log("error", "Attempt to open archive storage returned a driver without archive API support"); |
61 module:log("error", "mod_%s does not support archiving", | 62 module:log("error", "mod_%s does not support archiving", |
395 end | 396 end |
396 end | 397 end |
397 if not id and (archive.caps and archive.caps.truncate) then | 398 if not id and (archive.caps and archive.caps.truncate) then |
398 module:log("debug", "User '%s' over quota, truncating archive", room_node); | 399 module:log("debug", "User '%s' over quota, truncating archive", room_node); |
399 local truncated = archive:delete(room_node, { | 400 local truncated = archive:delete(room_node, { |
400 truncate = archive_item_limit - 1; | 401 truncate = archive_truncate; |
401 }); | 402 }); |
402 if truncated then | 403 if truncated then |
403 id, err = archive:append(room_node, nil, stored_stanza, time, with); | 404 id, err = archive:append(room_node, nil, stored_stanza, time, with); |
404 end | 405 end |
405 end | 406 end |