Notes: paged list with filters, stable cursors and a cheap total (#59) #62

Closed
kayg wants to merge 0 commits from issue/59-list-paging into dev
Owner

Closes #59.

API

notes.list (read-only, no idempotency key)

Send a query object to get one page:

{
  "limit": 50,
  "cursor": null,
  "order": "updated",
  "tag": "area",
  "kind": "daily",
  "pinned": true,
  "from_ms": 1767225600000,
  "to_ms": 1769904000000
}

Every field is optional, and {} means the first page of everything, newest change first.

field meaning
limit 1-500 (default 50)
cursor the next value from the previous page; opaque
order "updated" (default, newest change first), "created" (newest first, undated notes last) or "title" (A-Z). Ties break by id, so the order is stable.
tag that tag and every tag below it (area matches area/journal). A leading # is fine.
kind "daily" or "note"
pinned true or false
from_ms / to_ms created time range in ms: from inclusive, to exclusive

Unknown fields, a bad kind or a junk cursor return invalid_input. A cursor used with a different order is refused.

Reply:

{
  "items": [
    {
      "id": "day-2026-10-13",
      "path": "2026-10-13.md",
      "title": "2026-10-13",
      "kind": "daily",
      "snippet": "07:02 Morning pages #area/journal",
      "tags": ["area/journal"],
      "created_ms": 1791855720000,
      "updated_ms": 1791900000000,
      "pinned": false
    }
  ],
  "next": "7b226f72…",
  "total": 693,
  "incomplete": false
}
  • next is null on the last page.
  • total counts all matches across every page.
  • incomplete is true while the Home is still checking its folder after opening, so more notes may appear. Re-ask once it turns false, or follow the journal.
  • A note made in the app shows up before anyone types in it: title from its file name, empty snippet.

Legacy (deprecated, kept one release): no input, or null, returns { "notes": [{ "id", "path" }], "incomplete" } for every note at once. It costs about 0.35-0.5 s at 100k notes.

notes.pin (changes the note, so it needs an Idempotency-Key)

  • Input: { "id": "<note id>", "pinned": true }
  • Reply: { "id", "pinned", "version" }
  • It sets or removes calternal-pinned: true in the note's frontmatter through its room, like any edit. It's a calternal- key, so the info sheet hides it. The list reflects the pin after the note saves, about a second later, so the UI should flip it optimistically.

Live updates: list rows follow the journal. The notes.created, notes.saved, notes.changed, notes.renamed and notes.deleted events mean "refetch the visible page", or patch that one row by re-requesting it.

How it works

  • The list store: notes/meta.db is per person, rebuildable, synchronous=NORMAL, and versioned so a schema change rebuilds it. Each note is described exactly the way search describes it (shared code in search.rs), plus a snippet and the pin, so a tag means the same thing in the list, the sidebar and search.
  • Keeping it current:
    • The startup scan re-reads only notes whose stamp (size, mtime, path) changed, in parallel.
    • Every notes event refreshes that note in the background, with bursts batched.
    • incomplete stays true until the list has caught up.
  • Tag queries: tags are stored with their parents, so a tag filter is one exact index lookup and its total is one index count. A common tag walks the order index and stops after a page; a rare one (under 2,000 notes) collects and sorts its few notes.

Numbers

Measured on calternal-dev's SSD, at load average ~21 (the perf VM is busy), using the #44 fixtures with 100k notes and 412k tag rows. 200 requests each, over HTTP.

page p50 p95
first page ({}) 5.9 ms 9.5 ms
page 101 (cursor) 6.6 ms 11.3 ms
tag (20,825 notes) 5.6 ms 9.3 ms
daily 2.9 ms 4.8 ms
pinned 1.1 ms 1.7 ms
title order 5.9 ms 10.0 ms
created order 6.1 ms 9.6 ms
legacy unpaged 514 ms 585 ms

Gate: first page p95 under 20 ms. Met, along with every other page shape. Before the tag plan, the tag filter took 268 ms p95.

Opening a 100k Home:

  • Warm (list ready, incomplete: false): 2.8 s.
  • First build of the list store: 28.6 s. It happens once per Home, or again after a schema bump, and incomplete stays true while it runs. kayg's 693 notes take a fraction of a second. Speeding up the first build (prepared batch inserts) is a possible follow-up.

Tests

  • 5 new listing tests:
    • pages cover every note exactly once in all 3 orders
    • tag, kind and created-range filters, plus a bad cursor and a bad kind
    • a common tag (2,100 notes) pages the same in every order, nested tags included
    • pin and unpin, with the key removed from the file
    • the list stays live: a new note shows before typing, outside notes are tagged, deletes drop out
  • Also a cursor round-trip unit test.
  • The workspace passes 216 tests, 3 runs in a row, and clippy is clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T

Closes #59. ## API **`notes.list`** (read-only, no idempotency key) Send a query object to get one page: ```json { "limit": 50, "cursor": null, "order": "updated", "tag": "area", "kind": "daily", "pinned": true, "from_ms": 1767225600000, "to_ms": 1769904000000 } ``` Every field is optional, and `{}` means the first page of everything, newest change first. | field | meaning | |---|---| | `limit` | 1-500 (default 50) | | `cursor` | the `next` value from the previous page; opaque | | `order` | `"updated"` (default, newest change first), `"created"` (newest first, undated notes last) or `"title"` (A-Z). Ties break by id, so the order is stable. | | `tag` | that tag and every tag below it (`area` matches `area/journal`). A leading `#` is fine. | | `kind` | `"daily"` or `"note"` | | `pinned` | `true` or `false` | | `from_ms` / `to_ms` | created time range in ms: from inclusive, to exclusive | Unknown fields, a bad `kind` or a junk cursor return `invalid_input`. A cursor used with a different `order` is refused. Reply: ```json { "items": [ { "id": "day-2026-10-13", "path": "2026-10-13.md", "title": "2026-10-13", "kind": "daily", "snippet": "07:02 Morning pages #area/journal", "tags": ["area/journal"], "created_ms": 1791855720000, "updated_ms": 1791900000000, "pinned": false } ], "next": "7b226f72…", "total": 693, "incomplete": false } ``` - `next` is `null` on the last page. - `total` counts all matches across every page. - `incomplete` is `true` while the Home is still checking its folder after opening, so more notes may appear. Re-ask once it turns `false`, or follow the journal. - A note made in the app shows up before anyone types in it: title from its file name, empty snippet. **Legacy (deprecated, kept one release):** no input, or `null`, returns `{ "notes": [{ "id", "path" }], "incomplete" }` for every note at once. It costs about 0.35-0.5 s at 100k notes. **`notes.pin`** (changes the note, so it needs an `Idempotency-Key`) - Input: `{ "id": "<note id>", "pinned": true }` - Reply: `{ "id", "pinned", "version" }` - It sets or removes `calternal-pinned: true` in the note's frontmatter through its room, like any edit. It's a `calternal-` key, so the info sheet hides it. The list reflects the pin after the note saves, about a second later, so the UI should flip it optimistically. **Live updates:** list rows follow the journal. The `notes.created`, `notes.saved`, `notes.changed`, `notes.renamed` and `notes.deleted` events mean "refetch the visible page", or patch that one row by re-requesting it. ## How it works - **The list store:** `notes/meta.db` is per person, rebuildable, `synchronous=NORMAL`, and versioned so a schema change rebuilds it. Each note is described exactly the way search describes it (shared code in `search.rs`), plus a snippet and the pin, so a tag means the same thing in the list, the sidebar and search. - **Keeping it current:** - The startup scan re-reads only notes whose stamp (size, mtime, path) changed, in parallel. - Every notes event refreshes that note in the background, with bursts batched. - `incomplete` stays `true` until the list has caught up. - **Tag queries:** tags are stored with their parents, so a tag filter is one exact index lookup and its total is one index count. A common tag walks the order index and stops after a page; a rare one (under 2,000 notes) collects and sorts its few notes. ## Numbers Measured on calternal-dev's SSD, at load average ~21 (the perf VM is busy), using the #44 fixtures with 100k notes and 412k tag rows. 200 requests each, over HTTP. | page | p50 | p95 | |---|---|---| | first page (`{}`) | 5.9 ms | **9.5 ms** | | page 101 (cursor) | 6.6 ms | 11.3 ms | | tag (20,825 notes) | 5.6 ms | 9.3 ms | | daily | 2.9 ms | 4.8 ms | | pinned | 1.1 ms | 1.7 ms | | title order | 5.9 ms | 10.0 ms | | created order | 6.1 ms | 9.6 ms | | legacy unpaged | 514 ms | 585 ms | **Gate:** first page p95 under 20 ms. **Met, along with every other page shape.** Before the tag plan, the tag filter took 268 ms p95. **Opening a 100k Home:** - Warm (list ready, `incomplete: false`): 2.8 s. - First build of the list store: 28.6 s. It happens once per Home, or again after a schema bump, and `incomplete` stays `true` while it runs. kayg's 693 notes take a fraction of a second. Speeding up the first build (prepared batch inserts) is a possible follow-up. ## Tests - 5 new listing tests: - pages cover every note exactly once in all 3 orders - tag, kind and created-range filters, plus a bad cursor and a bad kind - a common tag (2,100 notes) pages the same in every order, nested tags included - pin and unpin, with the key removed from the file - the list stays live: a new note shows before typing, outside notes are tagged, deletes drop out - Also a cursor round-trip unit test. - The workspace passes 216 tests, 3 runs in a row, and clippy is clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Notes: paged list with filters, stable cursors and a cheap total (#59)
All checks were successful
CI / rust (pull_request) Successful in 1m1s
CI / web (pull_request) Successful in 43s
4ae6f09832
notes.list with a query object returns one page: keyset cursors over a
stable order (updated, created or title; ties by id), filters for tag
(with everything below it), kind, pinned and created range, a total, and
`incomplete`. Without input it still returns every note at once
(deprecated, kept for one release).

The list lives in a rebuildable per-person store (notes/meta.db): each
note described the way search describes it, plus a snippet and the pin.
The startup scan re-reads only notes whose stamp changed; every notes
event refreshes its note in the background; notes made in the app are
listed before anyone types. Tags are stored with their parents, so a
tag filter is one index lookup and its total one index count; common
tags walk the order index, rare ones sort their few notes.

notes.pin sets or removes `calternal-pinned: true` (a Calternal key, so
the info sheet hides it).

At 100k notes every page shape is under 12 ms p95 (gate: 20 ms).

Part of #59

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Yyy8fQGxPLkLa8v8NXz7T
Author
Owner

Reviewed by Claude: cursor paging with stable tie-break, tag hierarchy stored for one-lookup filters, rebuildable meta.db sharing the search doc reader. 100k first page p95 9.5 ms (gate 20 ms). CI green. Merging. Follow-up: batched inserts for the first 100k meta build (28.6 s).

Reviewed by Claude: cursor paging with stable tie-break, tag hierarchy stored for one-lookup filters, rebuildable meta.db sharing the search doc reader. 100k first page p95 9.5 ms (gate 20 ms). CI green. Merging. Follow-up: batched inserts for the first 100k meta build (28.6 s).
kayg closed this pull request 2026-10-13 19:52:49 +00:00
All checks were successful
CI / rust (pull_request) Successful in 1m1s
CI / web (pull_request) Successful in 43s

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
kayg/calternal!62
No description provided.