跳到正文
FunCoding

pagination

How list endpoints page through results. Read before adding a list endpoint or a limit parameter.

Star
8,225
许可证
Apache-2.0
最近提交
2026年12月1日

.claude/skills/pagination/SKILL.md

在 GitHub 上查看

Pagination

Never use limit/offset. Lists take limit + cursor.

  • Offset is slow: Postgres reads and discards every skipped row. A cursor is an indexed WHERE.
  • Offset is wrong when data changes: an insert repeats a row on the next page, a delete skips one.

Rules

  • Response is {items, has_more, next_cursor}, like SessionPage. Never a bare array.
  • Cursors are opaque base64url. Clients never build or parse them.
  • Sort ends with id so the order is total. The cursor holds every sort key.
  • Fetch limit + 1 to set has_more. No counts.
  • Filters are resent with every page; the cursor holds a position. It may also record the filters it was handed out for, and is then refused under others (a 400).
  • A bad cursor is a 400.
  • Index the sort keys behind the filter, e.g. (customer_id, updated_at DESC, id DESC).
  • A list that filters and sorts takes a body instead of query parameters: see the query skill.

Example: querySessions

Spec: SessionQuery carries limit and cursor in the body, and SessionPage is the 200.

Position, in internal/store/models.go:

type SessionPosition struct {
	UpdatedAt time.Time `json:"u"`
	ID        string    `json:"id"`
	Rank      float32   `json:"r,omitempty"`
}

Store, in Sessions.Select:

if after := filter.Cursor; after != nil {
	query = query.Where("(updated_at, id) < (?, ?)", after.UpdatedAt, after.ID)
}
query = query.Limit(SessionLimit(filter.Limit) + 1)

Handler: decodeCursor and encodeCursor in internal/api/cursor.go; page trims the extra row and says whether it was there. The session cursor also records which sort it came from, so a cursor from one sort is refused by another.

Live sessions that nothing records get the same cut and sort in Manager.find, on their created, which is truncated to microseconds (what Postgres keeps) so that a cursor from one half does not repeat the other. A recorded live session is listed through its row.

A text search sorts by relevance, and its cursor adds the rank: (rank, updated_at, id) < (?, ?, ?).

Go SDK: list methods return the page and take a cursor; Items.Unwind follows it.

Lists without a cursor yet

listCalls, listSimulationRuns and getCallEvents take a limit and no way to continue. listSimulationRuns refuses a limit over 500, and getCallEvents one over the 10,000 decisions a call keeps. listCalls answers 500 at most.

相似的 Skill

blender-motion-state-inspection

AFaffaan-m/ECC314k近 7 天新增 4,125 个 star

官方

slack-gif-creator

ANanthropics/skills203k近 7 天新增 3,333 个 star

精选

algorithmic-art

用 p5.js 生成流场和粒子系统,通过种子随机性创作原创算法艺术。

ANanthropics/skills203k近 7 天新增 3,333 个 star

moneyprinterturbo-video

HAharry0703/MoneyPrinterTurbo147k近 7 天新增 1,663 个 star

thinking-out-loud

SHShubhamsaboo/awesome-llm-apps146k近 7 天新增 895 个 star

design-motion

GAgarrytan/gstack143k近 7 天新增 636 个 star