diff --git a/99 Daily/2026-05-15.md b/99 Daily/2026-05-15.md index 79d772b..4e11c5a 100644 --- a/99 Daily/2026-05-15.md +++ b/99 Daily/2026-05-15.md @@ -85,3 +85,4 @@ tags: [daily] - 16:29 (1min) — session ended | `ai_leed` - 16:30 — session ended | `ai_leed` - 16:31 — session ended | `ai_leed` +- 16:33 — session ended | `ai_leed` diff --git a/raw/queries__pagination.md b/raw/_processed/queries__pagination.md similarity index 100% rename from raw/queries__pagination.md rename to raw/_processed/queries__pagination.md diff --git a/wiki/_master-index.md b/wiki/_master-index.md index 0aafae3..bfa52a4 100644 --- a/wiki/_master-index.md +++ b/wiki/_master-index.md @@ -35,7 +35,7 @@ This 3-hop pattern works for hundreds of articles without vector search. | [[wiki/reports/_index\|reports/]] | Weekly and monthly summaries — generate: `uv run python scripts/report-generator.py --weekly` | 1 | | [[wiki/infrastructure/_index\|infrastructure/]] | Server inventory: all 10 SSH hosts — optical, optical-dev, optical-prod, baic, librechat, modocmms, box-cli, aimpress, pve | 12 | | [[wiki/testing/_index\|testing/]] | Web app testing: functional, performance, security, UI types; TDD/BDD/Agile methodologies; Selenium/Cypress/Playwright/JMeter/OWASP ZAP tools | 1 | -| [[wiki/payloadcms/_index\|payloadcms/]] | Full Payload CMS reference — getting started, config, database (Postgres/MongoDB/SQLite), all 22 field types, access control, hooks, authentication (cookies, JWT, API keys, custom strategies, token data), admin UI, custom components, Lexical rich text, live preview, versions/drafts, Local/REST/GraphQL APIs, queries, plugins, jobs queue, upload, ecommerce, production deploy, TypeScript, migration guides, i18n, localization, hierarchy | 126 | +| [[wiki/payloadcms/_index\|payloadcms/]] | Full Payload CMS reference — getting started, config, database (Postgres/MongoDB/SQLite), all 22 field types, access control, hooks, authentication (cookies, JWT, API keys, custom strategies, token data), admin UI, custom components, Lexical rich text, live preview, versions/drafts, Local/REST/GraphQL APIs, queries, plugins, jobs queue, upload, ecommerce, production deploy, TypeScript, migration guides, i18n, localization, hierarchy | 127 | | [[wiki/shared-patterns/_index\|shared-patterns/]] | Oliver Agency standard library patterns: httpx, structlog, pydantic-settings, alembic — reuse before writing from scratch | 4 | | [[wiki/mistakes/_index\|mistakes/]] | Anti-patterns extracted from sessions — per-stack running lists (fastapi, react, docker, postgres, general) — injected at session start | 5 | diff --git a/wiki/payloadcms/_index.md b/wiki/payloadcms/_index.md index 57d9285..a1f12b8 100644 --- a/wiki/payloadcms/_index.md +++ b/wiki/payloadcms/_index.md @@ -127,3 +127,4 @@ | [[wiki/payloadcms/building-without-db-connection\|Building Without a DB Connection]] | Docker build fails when Next.js SSG calls Local API — two-phase `compile`/`generate` build modes, `force-dynamic` escape hatch, `NEXT_PUBLIC_` gotcha | raw/production__building-without-a-db-connection.md | 2026-05-15 | | [[wiki/payloadcms/production-preventing-abuse\|Production — Preventing API Abuse]] | Login rate limiting (maxLoginAttempts/lockTime), maxDepth, CSRF, CORS, GraphQL complexity limits, malicious file upload mitigation | raw/production__preventing-abuse.md | 2026-05-15 | | [[wiki/payloadcms/queries-depth\|Queries — Depth (Relationship Population)]] | depth=0 (IDs only) vs depth=N (full objects), defaultDepth config, field-level maxDepth cap, performance notes, GraphQL exception | raw/queries__depth.md | 2026-05-15 | +| [[wiki/payloadcms/queries-pagination\|Queries — Pagination]] | Default pagination (limit/page/pagination options), response shape (docs + metadata), limit:1 perf tip, disabling pagination for bulk ops | raw/queries__pagination.md | 2026-05-15 | diff --git a/wiki/payloadcms/queries-pagination.md b/wiki/payloadcms/queries-pagination.md new file mode 100644 index 0000000..93f2216 --- /dev/null +++ b/wiki/payloadcms/queries-pagination.md @@ -0,0 +1,102 @@ +--- +title: "Queries — Pagination" +aliases: [payload-pagination, payload-find-pagination] +tags: [payloadcms, queries, pagination, rest-api, local-api] +sources: [raw/queries__pagination.md] +created: 2026-05-15 +updated: 2026-05-15 +--- + +## Overview + +All Payload `find` operations are **paginated by default**. Responses wrap documents in a `docs` array alongside pagination metadata. + +## Options + +| Option | Default | Description | +|--------|---------|-------------| +| `limit` | `10` | Max documents returned per page | +| `page` | `1` | Which page to fetch | +| `pagination` | `true` | Set `false` to disable and return all docs | + +> `limit: 0` automatically disables pagination (same as `pagination: false`). + +## Local API + +```ts +const posts = await payload.find({ + collection: 'posts', + limit: 10, + page: 2, +}) +``` + +## REST API + +``` +GET /api/posts?limit=10&page=2 +``` + +## Response Shape + +```json +{ + "docs": [...], + "totalDocs": 6, + "limit": 10, + "totalPages": 1, + "page": 1, + "pagingCounter": 1, + "hasPrevPage": false, + "hasNextPage": false, + "prevPage": null, + "nextPage": null +} +``` + +| Field | Description | +|-------|-------------| +| `docs` | Array of documents for the current page | +| `totalDocs` | Total documents in the collection matching the query | +| `totalPages` | Total pages at the current `limit` | +| `pagingCounter` | Index of the first doc on this page | +| `hasPrevPage` / `hasNextPage` | Boolean navigation flags | +| `prevPage` / `nextPage` | Page numbers or `null` | + +## Performance Tips + +### Limit to 1 when querying by unique field + +```ts +await payload.find({ + collection: 'posts', + where: { slug: { equals: 'my-post' } }, + limit: 1, // no need to scan further +}) +``` + +### Disable pagination for bulk operations + +```ts +const all = await payload.find({ + collection: 'posts', + pagination: false, // skips COUNT query overhead +}) +``` + +Disabling pagination removes the `COUNT(*)` overhead — useful for migrations, exports, or scheduled jobs processing all documents. + +## Key Takeaways + +- All `find` queries return paginated results by default (`limit: 10`, `page: 1`) +- Response always has `docs[]` + metadata fields (`totalDocs`, `totalPages`, `hasNextPage`, etc.) +- Set `limit: 1` when querying by unique field (slug, email) for a fast DB lookup +- Set `pagination: false` (or `limit: 0`) to retrieve all documents in one call — avoids COUNT overhead +- Works identically across Local API, REST, and GraphQL (GraphQL has its own pagination shape) + +## Related + +- [[wiki/payloadcms/queries|Queries — Overview]] — where operators, sort, select, depth +- [[wiki/payloadcms/queries-depth|Queries — Depth]] — relationship population depth +- [[wiki/payloadcms/rest-api|REST API]] — full query param reference +- [[wiki/payloadcms/local-api|Local API]] — direct DB access patterns