add list_messages RPC to remove client-side N+1 #26

Closed
opened 2026-04-19 08:25:32 +00:00 by zaelgohary · 0 comments
Member

Clients that want all messages for one conversation currently have to call chatmessage.list (returns every message SID in the entire domain) and then fetch each one via chatmessage.get, discarding any whose conversation_sid doesn't match. For a modestly-populated DB (~200 messages across ~10 chats) this is ~200 JSON-RPC round trips to open a single conversation.

Proposed fix: expose a ConversationService.list_messages(conversation_sid: str) -> [ChatMessage] RPC that filters server-side and returns messages sorted by created_at ascending. Measured outcome in the messaging UI: chat open drops from ~51 RPCs to 3.

The ChatMessage.conversation_sid field is already marked [index] in the schema; a later follow-up could switch the impl to a true indexed lookup instead of the current O(N) scan.

Clients that want all messages for one conversation currently have to call `chatmessage.list` (returns every message SID in the entire domain) and then fetch each one via `chatmessage.get`, discarding any whose `conversation_sid` doesn't match. For a modestly-populated DB (~200 messages across ~10 chats) this is **~200 JSON-RPC round trips** to open a single conversation. **Proposed fix**: expose a `ConversationService.list_messages(conversation_sid: str) -> [ChatMessage]` RPC that filters server-side and returns messages sorted by `created_at` ascending. Measured outcome in the messaging UI: chat open drops from ~51 RPCs to 3. The `ChatMessage.conversation_sid` field is already marked `[index]` in the schema; a later follow-up could switch the impl to a true indexed lookup instead of the current O(N) scan.
zaelgohary changed title from perf: add ConversationService.list_messages(conversation_sid) to remove client-side N+1 to add list_messages RPC to remove client-side N+1 2026-04-19 08:32:18 +00:00
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
lhumina_code/hero_osis#26
No description provided.