Perf: Redundant permission queries + missing message index #86

Closed
opened 2026-07-08 02:40:33 +00:00 by icub3d · 0 comments
Owner

Category: Performance — found in code review 2026-07-07.

Problem

  • server/src/permissions.rs:158 (effective_permissions) calls compute_base_permissions (which already runs list_member_roles) and then calls list_member_roles again at :173, plus fetches the everyone role every call. Every message send/list/reaction pays 2× list_member_roles + a get_role("everyone").
  • list_messages orders by id DESC (ULID = chronological) but the only index is idx_messages_channel_created (channel_id, created_at) — it doesn't cover ordering by id or the thread_id IS NULL filter, so SQLite filters then sorts.

Fix

  • Have compute_base_permissions return the role list so effective_permissions reuses it; cache the everyone role.
  • Add an index (channel_id, thread_id, id) so the paginated scan is index-ordered.
**Category: Performance** — found in code review 2026-07-07. ## Problem - `server/src/permissions.rs:158` (`effective_permissions`) calls `compute_base_permissions` (which already runs `list_member_roles`) and then calls `list_member_roles` **again** at `:173`, plus fetches the `everyone` role every call. Every message send/list/reaction pays 2× `list_member_roles` + a `get_role("everyone")`. - `list_messages` orders by `id DESC` (ULID = chronological) but the only index is `idx_messages_channel_created (channel_id, created_at)` — it doesn't cover ordering by `id` or the `thread_id IS NULL` filter, so SQLite filters then sorts. ## Fix - [ ] Have `compute_base_permissions` return the role list so `effective_permissions` reuses it; cache the `everyone` role. - [ ] Add an index `(channel_id, thread_id, id)` so the paginated scan is index-ordered.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
icub3d/decentcom#86
No description provided.