diff mod_groups_internal/mod_groups_internal.lua @ 4386:6357ac65b4eb

mod_groups_internal: allow delay of roster sync on group change This is useful when executing a bulk change (e.g. a creation of a group with many members) to avoid O(n^3).
author Jonas Schäfer <jonas@wielicki.name>
date Mon, 25 Jan 2021 21:33:38 +0100
parents dfb34cc97028
children 7de3c955cfe2
line wrap: on
line diff
--- a/mod_groups_internal/mod_groups_internal.lua	Mon Jan 25 21:32:53 2021 +0100
+++ b/mod_groups_internal/mod_groups_internal.lua	Mon Jan 25 21:33:38 2021 +0100
@@ -157,7 +157,7 @@
 	return nil, "internal-server-error";
 end
 
-function add_member(group_id, username)
+function add_member(group_id, username, delay_update)
 	local group_info = group_info_store:get(group_id);
 	if not group_info then
 		return nil, "group-not-found";
@@ -165,7 +165,9 @@
 	if not group_memberships:set(group_id, username, {}) then
 		return nil, "internal-server-error";
 	end
-	do_all_group_subscriptions_by_group(group_id);
+	if not delay_update then
+		do_all_group_subscriptions_by_group(group_id);
+	end
 	return true;
 end
 
@@ -180,6 +182,10 @@
 	return true;
 end
 
+function sync(group_id)
+	do_all_group_subscriptions_by_group(group_id)
+end
+
 -- Returns iterator over group ids
 function groups()
 	return group_info_store:users();