comparison 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
comparison
equal deleted inserted replaced
4385:dfb34cc97028 4386:6357ac65b4eb
155 return group_info_store:set(group_id, nil); 155 return group_info_store:set(group_id, nil);
156 end 156 end
157 return nil, "internal-server-error"; 157 return nil, "internal-server-error";
158 end 158 end
159 159
160 function add_member(group_id, username) 160 function add_member(group_id, username, delay_update)
161 local group_info = group_info_store:get(group_id); 161 local group_info = group_info_store:get(group_id);
162 if not group_info then 162 if not group_info then
163 return nil, "group-not-found"; 163 return nil, "group-not-found";
164 end 164 end
165 if not group_memberships:set(group_id, username, {}) then 165 if not group_memberships:set(group_id, username, {}) then
166 return nil, "internal-server-error"; 166 return nil, "internal-server-error";
167 end 167 end
168 do_all_group_subscriptions_by_group(group_id); 168 if not delay_update then
169 do_all_group_subscriptions_by_group(group_id);
170 end
169 return true; 171 return true;
170 end 172 end
171 173
172 function remove_member(group_id, username) 174 function remove_member(group_id, username)
173 local group_info = group_info_store:get(group_id); 175 local group_info = group_info_store:get(group_id);
178 return nil, "internal-server-error"; 180 return nil, "internal-server-error";
179 end 181 end
180 return true; 182 return true;
181 end 183 end
182 184
185 function sync(group_id)
186 do_all_group_subscriptions_by_group(group_id)
187 end
188
183 -- Returns iterator over group ids 189 -- Returns iterator over group ids
184 function groups() 190 function groups()
185 return group_info_store:users(); 191 return group_info_store:users();
186 end 192 end