Perf: N+1 query storm when listing messages (batch enrichment) #84
Labels
No labels
area:api
area:core
area:docs
area:infra
area:ux
dependencies
documentation
duplicate
good first issue
help wanted
invalid
question
rust
status:complete
status:partial
status:planned
type:bug
type:design
type:feature
type:infra
type:refactor
type:refactor
type:research
type:ux
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
icub3d/decentcom#84
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Category: Performance — found in code review 2026-07-07.
Problem
server/src/messages/handlers.rs:90(enrich_message) runs 3 separate queries per message (list_attachments_for_message,list_reaction_counts,get_thread_summary), awaited in aforloop (:221). A 50-message page ≈ 150 sequential round-trips. A batchedlist_thread_summaries(&[id])already exists (storage/sqlite/threads.rs:91) but the list path uses the single-row variant.Fix
WHERE message_id IN (...), reaction counts grouped by message_id, and the existinglist_thread_summaries. Assemble in memory.list_attachments_for_messages(&[String])andlist_reaction_counts_for_messages(&[String], viewer).Turns ~150 queries into 3.