diff options
author | Kim Alvefur <zash@zash.se> | 2017-09-12 14:42:56 +0200 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2017-09-12 14:42:56 +0200 |
commit | 863374e1643db918d328eac3185dab7b2abb0404 (patch) | |
tree | 495d413d88b1ef6198a82097b669a6345633d559 /plugins/mod_mam | |
parent | a5f43007f15cd3673ec0bf16f9644188624f541a (diff) | |
download | prosody-863374e1643db918d328eac3185dab7b2abb0404.tar.gz prosody-863374e1643db918d328eac3185dab7b2abb0404.zip |
mod_mam: Use a FIFO queue for scheduling archive expiry
Diffstat (limited to 'plugins/mod_mam')
-rw-r--r-- | plugins/mod_mam/mod_mam.lua | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/plugins/mod_mam/mod_mam.lua b/plugins/mod_mam/mod_mam.lua index 32dd0169..7511a1bc 100644 --- a/plugins/mod_mam/mod_mam.lua +++ b/plugins/mod_mam/mod_mam.lua @@ -56,6 +56,13 @@ local use_total = true; local cleanup; +local function schedule_cleanup(username) + if cleanup and not cleanup[username] then + table.insert(cleanup, username); + cleanup[username] = true; + end +end + -- Handle prefs. module:hook("iq/self/"..xmlns_mam..":prefs", function(event) local origin, stanza = event.origin, event.stanza; @@ -97,7 +104,7 @@ module:hook("iq-set/self/"..xmlns_mam..":query", function(event) local query = stanza.tags[1]; local qid = query.attr.queryid; - if cleanup then cleanup[origin.username] = true; end + schedule_cleanup(origin.username); -- Search query parameters local qwith, qstart, qend; @@ -304,7 +311,7 @@ local function message_handler(event, c2s) local id = ok; clone_for_other_handlers:tag("stanza-id", { xmlns = xmlns_st_id, by = store_user.."@"..host, id = id }):up(); event.stanza = clone_for_other_handlers; - if cleanup then cleanup[store_user] = true; end + schedule_cleanup(store_user); module:fire_event("archive-message-added", { origin = origin, stanza = clone_for_storage, for_user = store_user, id = id }); end else @@ -353,13 +360,13 @@ if cleanup_after ~= "never" then pcall(function () -- If this works, then we schedule cleanup for all known users on startup for user in um.users(module.host) do - cleanup[user] = true; + schedule_cleanup(user); end end); -- At odd intervals, delete old messages for one user module:add_timer(math.random(10, 60), function() - local user = next(cleanup); + local user = table.remove(cleanup, 1); if user then module:log("debug", "Removing old messages for user %q", user); local ok, err = archive:delete(user, { ["end"] = os.time() - cleanup_after; }) |