There was an bad query that was used to return the count of users with chat enabled in the chat group serializer and it was taking ~30s for your account which is the request timeout on our hosting (hence why you were getting it “randomly”)
main ← fix-chatables-timeout
merged 06:05PM - 29 Dec 25 UTC
When searching for `chatables`, groups matching the search term are serialized. … The serializer was computing `chat_enabled_user_count` by loading **ALL** users from each group into memory and iterating through them in Ruby:
```ruby
object.human_users.count { |user| user.user_option&.chat_enabled }
```
On large sites, groups like `trust_level_0` can have tens of thousands of users. This caused serialization to be extremely slow, potentially hitting request timeouts and resulting in 502 errors.
The fix uses a SQL COUNT query instead, which completes in milliseconds. The result is also memoized since `can_chat` calls `chat_enabled_user_count` internally.
Ref: https://meta.discourse.org/t/392286
3 Likes