Skip to content

Conversation

evenkkl
Copy link
Member

@evenkkl evenkkl commented Nov 22, 2026

Closes #96

What was done

  • Server: searchAlbums now runs only the cursor page query. totalCount, genreFacets, decadeFacets, countryFacets and reviewedCount are AlbumConnection field resolvers in server/src/resolvers.ts, so they run only when an operation selects them. schema.graphql is unchanged.
  • Client: Load more uses a new SearchAlbumsPage query (client/src/api/searchAlbums.ts) with only edges and pageInfo. The searchAlbums merge in client/src/api/client.ts keeps the first page's count and facets ({ ...existing, ...incoming, edges }). Codegen output regenerated.
  • Docs: short notes in docs/scalability.md and the README scalability section, plus a row in docs/AI-USAGE.md.

What was tested

  • New server/src/search/aggregates.test.ts runs both operations through Yoga against a database stand-in that records SQL: the first page runs 6 queries (page + 5 aggregates), Load more runs 1.
  • client/src/api/client.test.ts: the page query validates against the schema, selects only edges and pageInfo, and selects the same album fields as SearchAlbums; after a Load more page without aggregates, the cache still has page one's count and all facets.
  • pagination.test.tsx mocks now serve Load more with SearchAlbumsPage. MockLink matches on the query document, so a Load more sent with the full query would fail these tests. The existing "Showing N of 40" checks after Load more still pass.
  • facets.postgres.test.ts now calls the AlbumConnection resolvers.
  • pnpm format:check, pnpm lint (0 warnings), typecheck in both workspaces, client build: pass.
  • Server: 86 passed, 56 skipped (Postgres) · Client: 209 passed.
  • Against PGlite: facets (8), search (11) and sort (8) Postgres tests pass; crate (14) passes with a one-connection pool. The two search-history row-lock tests need two connections and can't run on PGlite; they don't touch search.
  • One review-form focus test failed once in a full client run and passed on rerun; that file is not changed here.

searchAlbums now runs only the page query. totalCount, the three facet
lists and reviewedCount are AlbumConnection field resolvers, so they run
only when an operation selects them. The schema is unchanged.

The client sends Load more with a new SearchAlbumsPage query that asks
for edges and pageInfo only. The searchAlbums merge keeps the first
page's count and facets when a later page leaves them out.

Tests: a server test counts the SQL a first page and a Load more request
run (6 vs 1); client tests check that the page query omits the
aggregates, selects the same album fields, and that the cache keeps page
one's count and facets. Pagination mocks now serve Load more with the
page query.
@evenkkl evenkkl requested a review from a team as a code owner November 22, 2026 12:19
@evenkkl evenkkl self-assigned this Nov 22, 2026
@evenkkl evenkkl changed the title perf: #96 skip count and facet queries on Load more fix: #96 skip count and facet queries on Load more Nov 22, 2026
Copy link
Member

@erikhfj erikhfj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the server resolvers, client query/cache policy, tests, and docs. Moving the five aggregates to AlbumConnection field resolvers, introducing SEARCH_ALBUMS_PAGE for Load more, and preserving the first page's count and facets in the Apollo searchAlbums merge policy ({ ...existing, ...incoming, edges }) is clean and well-tested (especially the Yoga SQL-recording test and the selection-parity check in client.test.ts). CI is green — approving.

@erikhfj erikhfj merged commit af1000c into main Nov 22, 2026
3 checks passed
@erikhfj erikhfj deleted the perf/96-skip-aggregates-on-load-more branch November 22, 2026 16:45
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid recomputing facets and totalCount on Load more
2 participants