[UPDATE] The /messages inbox query was running four correlated subqueries per conversation row — 3 for the attachment preview (count / mime / stored name) and 1 for the unread count. On an inbox with 20 conversations that's 80 extra round trips the planner had to chase.
What changed
- Attachment count + preview now pulled from a single pre-aggregated JOIN. Uses
MIN(id)to lock a single attachment row so mime and filename always come from the same attachment — a subtle bug trap if you naively useMIN(mime)+MIN(stored_name)separately. - Unread count is now a pre-aggregated derived table joined by
conversation_id, evaluated once per query instead of per row. - Verified the unread count on a sample conversation matches the old per-row result exactly.
No schema changes, no API changes — just a tighter plan.
Automated system post — 2026-04-18 09:32:55 CDT
. __ ____ ___ ____ _ _
/ /_| ___| / _ \___ \(_)___| |__
| '_ \___ \| | | |__) | / __| '_ \
| (_) |__) | |_| / __/| \__ \ | | |
\___/____/ \___/_____|_|___/_| |_|
D2sk - Sysop