Changeset

10682:62ef68f95b6f 0.11

mod_mam,mod_muc_mam: Allow other work to be performed during archive cleanup (fixes #1504) This lets Prosody handle socket related work between each step in the cleanup in order to prevent the server from being completely blocked during this. An async storage backend would not need this but those are currently rare.
author Kim Alvefur <zash@zash.se>
date Wed, 11 Mar 2020 21:15:01 +0100
parents 10681:e531273341d3
children 10683:2f0b7f1d5e75 10690:27d15097c235
files plugins/mod_mam/mod_mam.lua plugins/mod_muc_mam.lua
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_mam/mod_mam.lua	Wed Mar 11 18:07:03 2020 +0100
+++ b/plugins/mod_mam/mod_mam.lua	Wed Mar 11 21:15:01 2020 +0100
@@ -362,7 +362,8 @@
 		end
 	end
 
-	cleanup_runner = require "util.async".runner(function ()
+	local async = require "util.async";
+	cleanup_runner = async.runner(function ()
 		local users = {};
 		local cut_off = datestamp(os.time() - cleanup_after);
 		for date in cleanup_storage:users() do
@@ -391,6 +392,9 @@
 				cleanup_map:set(cut_off, user, true);
 				module:log("error", "Could not delete messages for user '%s': %s", user, err);
 			end
+			local wait, done = async.waiter();
+			module:add_timer(0.01, done);
+			wait();
 		end
 		module:log("info", "Deleted %d expired messages for %d users", sum, num_users);
 	end);
--- a/plugins/mod_muc_mam.lua	Wed Mar 11 18:07:03 2020 +0100
+++ b/plugins/mod_muc_mam.lua	Wed Mar 11 21:15:01 2020 +0100
@@ -437,7 +437,8 @@
 		end
 	end
 
-	cleanup_runner = require "util.async".runner(function ()
+	local async = require "util.async";
+	cleanup_runner = async.runner(function ()
 		local rooms = {};
 		local cut_off = datestamp(os.time() - cleanup_after);
 		for date in cleanup_storage:users() do
@@ -466,6 +467,9 @@
 				cleanup_map:set(cut_off, room, true);
 				module:log("error", "Could not delete messages for room '%s': %s", room, err);
 			end
+			local wait, done = async.waiter();
+			module:add_timer(0.01, done);
+			wait();
 		end
 		module:log("info", "Deleted %d expired messages for %d rooms", sum, num_rooms);
 	end);