diff --git a/plugins/chat/app/services/chat/auto_remove/handle_category_updated.rb b/plugins/chat/app/services/chat/auto_remove/handle_category_updated.rb index d66cb933d20..0918e986e30 100644 --- a/plugins/chat/app/services/chat/auto_remove/handle_category_updated.rb +++ b/plugins/chat/app/services/chat/auto_remove/handle_category_updated.rb @@ -59,11 +59,16 @@ module Chat end def remove_users_without_channel_permission(users:, category_channel_ids:) - memberships_to_remove = - Chat::Action::CalculateMembershipsForRemoval.call( - scoped_users: users, - channel_ids: category_channel_ids, + memberships_to_remove = [] + + users.find_in_batches do |batch_users| + memberships_to_remove.concat( + Chat::Action::CalculateMembershipsForRemoval.call( + scoped_users: batch_users, + channel_ids: category_channel_ids, + ), ) + end return if memberships_to_remove.blank?