feat(api): paginate the contact, group, and chat list endpoints - #401
Merged
Conversation
The contact/group/chat list endpoints serialized the operator's entire address book / group / chat set into a single response — a heap/GC hazard for very large accounts. Add optional limit/offset query params (clamped [1,1000]) with a safe default cap of 1000, applied in the service layer. Chats are sorted most-recent- first before capping so a bounded response is the newest chats, not an arbitrary slice. Pagination is applied at the HTTP/service boundary only: the engine still returns the full set to in-process callers (plugins use the engine directly), so they are unaffected. Behavior change (warrants a minor release): a list with >1000 items is now capped by default; clients page beyond the first window via offset.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GET /sessions/:id/contacts,/groups, and/chatspreviously serialized the linked account's entire address book / group / chat set into a single JSON response. For a large account (tens of thousands of contacts) that is a multi-MB heap allocation + GC/event-loop pressure per call, and the rate limiter caps request rate, not response size — so it degrades every session sharing the process.This adds opt-in pagination:
limit(clamped[1, 1000], NaN-safe) andoffsetquery params on all three endpoints.limitis omitted.paginate()helper. The engine still returns the full set to in-process callers — plugins call the engine directly (plugin-loader.service.ts), so they are unaffected.Compatibility
offset.Tests (TDD)
paginate.spec.ts— default cap, explicit-limit clamp, offset, NaN-safety, under-cap passthrough.contact.service/group.service/session.servicespecs — cap at 1000,limit/offsetapplied, chats sorted most-recent-first; the synchronous "session not started" 400 guard is preserved.Risk
Low/medium. Additive query params with a high default cap; the only behavior delta is the default truncation of >1000-item lists (documented). No engine-interface or adapter change; plugins unaffected.