# Timeouts do Chat Pitchfork: respostas criam tópicos silenciosamente e o rastreamento automático infla com o tempo

**URL:** https://meta.discourse.org/t/chat-pitchfork-timeouts-replies-silently-create-threads-and-auto-tracking-bloats-over-time/401067
**Category:** Bug
**Tags:** chat
**Created:** [Abril 20, 2026, 6:47pm UTC](https://meta.discourse.org/t/chat-pitchfork-timeouts-replies-silently-create-threads-and-auto-tracking-bloats-over-time/401067 "2026-04-20T18:47:10Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [Abril 21, 2026, 7:01am UTC](https://meta.discourse.org/t/chat-pitchfork-timeouts-replies-silently-create-threads-and-auto-tracking-bloats-over-time/401067/2 "2026-04-21T07:01:37Z")

</div>

Que relatório incrível!

Comecei a analisar isso e, nos meus testes, obtive uma melhoria de desempenho de 50x com:

> <https://github.com/discourse/discourse/pull/39398>
>
> Rewrites the channel and thread unread queries to use a CTE that
> picks the candi…date set up front, followed by LATERAL subqueries
> for each aggregate. The previous form used three correlated
> subqueries that each re-joined the user's full membership lists,
> and packed the unread predicate into a single OR-bag that forced
> a sequential scan over every message past last\_read\_message\_id.
> 
> The channel query now:
> \- Limits candidate channels in a CTE before aggregating.
> \- Splits unread\_count into three additive, index-friendly pieces
> (standalone messages, thread original messages, and DM thread
> replies) instead of one OR branch.
> \- Pushes the muted check into a CASE on the outer row.
> 
> The thread query now:
> \- Orders candidate memberships by last\_message\_id and caps them
> at MAX\_THREADS in the CTE, so recent threads always win.
> \- Derives unread and watched counts from a single aggregate
> switched by notification\_level.
> \- Skips threads whose channel membership is missing.
> 
> Also adds a covering index on chat\_messages(thread\_id, id) INCLUDE
> (user\_id) WHERE deleted\_at IS NULL to support the thread aggregates
> as index-only scans, and adds specs for the orphaned-thread case
> and the MAX\_THREADS recency cap.
> 
> \---
> 
> This gives this about 50x perf improvement in testing

Provavelmente precisaremos de muito mais testes, mas o lado positivo é que um pequeno bug aqui significará apenas que as contagens estarão um pouco fora do esperado. Precisamos reduzir a carga, não temos outra opção.

---

_[View the full topic](https://meta.discourse.org/t/chat-pitchfork-timeouts-replies-silently-create-threads-and-auto-tracking-bloats-over-time/401067)._
