mirror of
https://github.com/discourse/discourse.git
synced 2025-03-03 17:59:20 +00:00
PERF: Reduce mem allocation of Chat::AutoRemove::HandleCategoryUpdated
(#28393)
This is a follow-up to 671f40ce07ebda14e4655cb85ce4794b859023f0 and ed11ee9d057160e5c1b0d1a86c9e94582d8fafd0. While the optimisations in the previous commits were sound, it did not resolve the memory bloat we were seeing. It turns out that we call `.blank?` on the model's result if the model has not been marked optional. The problem with this is that if the model returns an ActiveRecord relation, calling `.blank?` on the relation basically loads everything into memory. Therefore, this commit removes `users` as a model in the since it really isn't a model but just a relation.
This commit is contained in:
parent
931485b7c1
commit
de79e5628e
@ -19,7 +19,6 @@ module Chat
|
||||
policy :chat_enabled
|
||||
model :category
|
||||
model :category_channel_ids
|
||||
model :users
|
||||
step :remove_users_without_channel_permission
|
||||
step :publish
|
||||
|
||||
@ -47,7 +46,10 @@ module Chat
|
||||
Chat::Channel.where(chatable: category).pluck(:id)
|
||||
end
|
||||
|
||||
def fetch_users(category_channel_ids:)
|
||||
def remove_users_without_channel_permission(category_channel_ids:)
|
||||
memberships_to_remove =
|
||||
Chat::Action::CalculateMembershipsForRemoval.call(
|
||||
scoped_users_query:
|
||||
User
|
||||
.real
|
||||
.activated
|
||||
@ -55,13 +57,7 @@ module Chat
|
||||
.not_staged
|
||||
.joins(:user_chat_channel_memberships)
|
||||
.where("user_chat_channel_memberships.chat_channel_id IN (?)", category_channel_ids)
|
||||
.where("NOT admin AND NOT moderator")
|
||||
end
|
||||
|
||||
def remove_users_without_channel_permission(users:, category_channel_ids:)
|
||||
memberships_to_remove =
|
||||
Chat::Action::CalculateMembershipsForRemoval.call(
|
||||
scoped_users_query: users,
|
||||
.where("NOT admin AND NOT moderator"),
|
||||
channel_ids: category_channel_ids,
|
||||
)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user