Skip to content

AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.

9.4 KB
Raw Blame

Keep note ordering after editing

简体中文 · Issue #750

Problem and outcome

The report describes Windows v2.16.1 moving an edited note to the top of a notebook sorted by title A–Z. The desktop query uses SQLite NOCASE, whereas cache updates use Chinese locale comparison. An isolated source-level reproduction changes the order of distinct Chinese titles after a body-only edit. Confirm the actual behavior in the latest official desktop release before changing product code.

Allowed changes and acceptance

  1. Install the latest official macOS release on the available machine through the built-in updater or the official installer. Keep an official installer available for recovery. Use an isolated application profile and local test instance; do not edit or migrate the user's real notes. Reproduce title A–Z → edit body → return through the packaged application's UI and retain the relevant before/after evidence. Report Windows-specific verification separately.
  2. If reproduced, correct list updates so editing a body does not change the relative order of distinct, unchanged titles. Keep the active sort selection. Actual title changes, equal-title tie breaks, new notes and ID remapping must remain consistent with the ordering used by that list's repository. Cover title A–Z and Z–A and retain the existing created/updated ordering, filters, notebook/tag constraints, counts and pagination entry points.
  3. Do not introduce full-library reads, full-library client sorting, extra network calls on body-only saves, migrations, indexes or new dependencies. Work with the loaded list/cache or the existing bounded repository query. Compare the affected save/update work with the baseline using representative cached-list sizes, and verify page boundaries and query counts.
  4. Before implementation, extend the existing cache regression coverage to fail for the reproduced behavior. Verify the fixed edit-and-return flow in the desktop runtime, including a title change and a multi-page list. Reuse the existing focused tests and run bun run typecheck, bun run typecheck:mobile and bun run build:web once for the final candidate.

Boundaries, risk and recovery

This change restores the selected list ordering; it does not redefine locale sorting, pinning priority or untitled-note display. Native Android/iOS clients, storage/authentication/synchronization mechanisms, installation/update mechanisms, server deployment, releases and version numbers remain unchanged. Keep unrelated sharing and backup behavior unchanged.

The value is predictable navigation after editing. The main risk is disagreement between cache ordering and repository pagination, causing misplaced or duplicated visible notes. Keep query parameter formats and paged-loading entry points intact and verify the loaded page boundary. Roll back the affected list-update code if needed; no data migration is planned. The retained official installer can reinstall v2.16.1 if application recovery is needed. Windows and other unavailable platforms require their own runtime verification.

Implementation decisions and completion

The installed official v2.16.1 reproduces the defect: 中文笔记 → 笔记整理 → 阿尔法 changes to 阿尔法 → 笔记整理 → 中文笔记 after a body-only save. The title is unchanged. See the before/after screenshots in evidence.

Keep the existing repository's ordering authoritative. Desktop title-cache ordering will match the sidecar's SQLite COALESCE(title, excerpt) COLLATE NOCASE, then descending update timestamp and ID. SQLite folds ASCII case only; do not substitute language-aware ordering or trim/fallback rules that differ from the query. Browser cache behavior and the sidecar query remain unchanged. Only already-loaded summaries are sorted, as before; no additional repository/network request or full-library read is introduced. This avoids changing indexed queries, pagination or desktop native code to repair a renderer-cache mismatch.

The ID tie break must also use SQLite's UTF-8 binary ordering: restored memo IDs accept non-ASCII strings, whose UTF-16 JavaScript ordering can differ. Share the scalar comparison implementation between binary IDs and ASCII-case-insensitive titles without changing accepted inputs. For a newly seen note in a multi-page desktop title list, order it with all loaded pages, not just the first page. Preserve the existing extra insertion slot in the first page so the newly created/selected note stays in the cache, retain page parameters, and update cached totals consistently. Do not discard notes or eagerly fetch unloaded pages; existing overlapping-page deduplication remains in use.

Newly fetched pages can arrive after a cached title edit/insertion, bypassing the cache-update helper. Apply the same desktop title sorter to the already-loaded, deduplicated display list so the following page cannot reintroduce an out-of-order edited note. This changes only the desktop title-list projection in WorkspaceApp; other browser/sort projections remain unchanged. It adds no data read and does not sort unloaded notes.

Always preserving offset cursors was superseded by a real pagination counterexample: changing a prefix note's title to sort last can make the next offset skip the following source note entirely. For desktop title lists only, move the last-page offset back for prefix entries removed, deduplicated or sorted beyond the previous prefix boundary by a title edit, backdated update timestamp or ID remap. Infer the conservative prefix from that offset, so repeatedly editing a note already outside it does not keep rewinding. Ordinary body saves with nondecreasing timestamps and changes within the prefix keep the cursor; other cursors/page parameters remain unchanged. The next ordinary page load fills the gap with bounded overlap; do not trigger a fetch, retry, count or full-library scan. The overlap can require an additional bounded page when the source ends exactly on a page boundary. The 100-note/50-note-page regression fetches 51 remaining rows in two pages, versus 50 in one without the edit; repeated edits of the same outlier do not add more overlap.

Completion check

  • Official v2.16.1 was installed through the existing updater and reproduced the edit-body → upper-left Back flow in an isolated macOS profile. The original reproduction screenshots and official installer remain available.
  • Desktop title order now matches SQLite NOCASE plus UTF-8 binary ID ties, including non-ASCII restored IDs. Cached insertion orders all loaded pages. Cache updates and the loaded-list display share one sorter, so subsequent pages cannot reintroduce an out-of-order edited note. Conditional offset overlap prevents skipped source rows after a prefix note moves out through renaming, backdated timestamps or ID remapping; repeated edits outside the prefix do not keep rewinding. No input limit, proxy/retry/fallback, immediate data request, migration or dependency was added.
  • All 27 focused cache/runtime tests pass, with SQLite executing the actual sidecar ORDER BY as the oracle. Tests that exposed the review findings failed before their corresponding repairs. Coverage includes both directions, title fallback/NUL/Unicode, equal-title timestamp and ID ties, insertion, remapping, active-cache updates without query-function calls, and loading through to the complete source after cursor repair. Final Web type checking and the desktop Web build pass. Web/mobile type checks and the desktop Web build also passed on the isolated PR branch based on current upstream main.
  • Original A–Z/Z–A body-edit, rename and 120-note loaded-page evidence remains applicable to those inputs. A final native macOS candidate using Electron 44.7 and the unchanged official sidecar also exercised the newly found failure: rename a first-page note to sort near the end, then continue scrolling. The completed list showed 123 / 123 fixture notes rather than losing a source row; see the final pagination screenshot. All operations used the isolated local fixture, not the user's Cloudflare data.
  • The final local microbenchmark includes cache update plus the loaded-list Map/display projection, 20% duplicate titles, increasing save timestamps, 50-summary pages, 10 warm-ups and 100 samples. For 5,000 loaded summaries, median body-update/projection time was 6.704 → 1.101 ms; new insertion/projection took 2.977 ms. This excludes React rendering, native/database/network work and production latency. The full series is in performance evidence. Normal body saves add no cursor work or data read. A moved-out prefix member adds bounded overlap to the next ordinary page, not an immediate read or per-page full scan.
  • Correctness, simplification and design-fit review of the final affected paths has no unresolved substantive finding within this scope. One comparison implementation serves both cache and display; no additional sorting algorithm or data source was introduced. The product diff is limited to memo-list-cache.ts and the desktop-title projection in WorkspaceApp.tsx; tests/documentation/evidence cover that change. Sharing and backup behavior remain unchanged. Release/installer validation is outside this source change; Windows-specific UI verification requires a Windows environment.