Skip to content

perf(api): push recommendations keyset pagination into the store read #981

Open

Description

@cristim

Follow-up from #974 (keyset pagination for GET /api/recommendations, #723).

Problem

#974 bounds the response per page. Each page request still loads the full filtered recommendation set via ListRecommendations (ListStoredRecommendations has no ORDER BY/LIMIT/cursor), unmarshals it, and sorts it in memory just to return one page. Walking an 8,000-row tenant in 1,000-row pages therefore loads and sorts 8,000 rows eight times, and per-request memory still grows with tenant size.

Suggested fix

Push the keyset boundary (id > cursor) and LIMIT into the store read, with a deterministic ORDER BY. Compute the full-set summary and regions with a separate aggregate query, so page reads stay O(page).

Source: CodeRabbit finding on #974 (thread 4294696025), triaged as out of scope there.

Activity

  1. IAmJSD commented on Oct 22, 2026

    @IAmJSD
    Collaborator

    Claiming: working on this

  2. self-assigned this
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions