Skip to content

Refactor save_note to use cache-driven slug collision handling and add tests#889

Merged
multiplex55 merged 1 commit intomasterfrom
codex/refactor-save_note-in-note.rs
Feb 17, 2026
Merged

Refactor save_note to use cache-driven slug collision handling and add tests#889
multiplex55 merged 1 commit intomasterfrom
codex/refactor-save_note-in-note.rs

Conversation

@multiplex55
Copy link
Copy Markdown
Owner

Motivation

  • Remove the pre-save load_notes() call that was used only for slug awareness and rely on the in-memory cache for slug collision context.
  • Make slug collision handling deterministic by seeding unique_slug from known cached slugs while excluding the current note’s path/slug.
  • Preserve a single authoritative post-write cache refresh via refresh_cache() and add regression tests for common edge cases.

Description

  • Replace the pre-save load_notes() with an existing_slugs set derived from CACHE.lock()?.notes that filters out the current note by path/slug.
  • Seed deterministic slug generation by calling reset_slug_lookup() and register_slug() for cached slugs and then using unique_slug() when note.slug is empty.
  • Add an explicit cached-slug collision guard before writing (if existing_slugs.contains(&slug) && note.path != path && !overwrite { return Ok(false); }) while keeping refresh_cache() as the single refresh after write.
  • Add regression tests: save_existing_note_succeeds_without_overwrite, save_as_new_generates_unique_slug_from_cache, and save_note_renames_slug_and_path to cover overwrite, save-as-new slug generation, and rename behavior.

Testing

  • Ran cargo fmt --all which succeeded.
  • Attempted to run the new tests via cargo test save_note_, but the build aborted due to a missing system dependency required by a transitive crate (alsa/alsa.pc), so the test run could not complete in this environment.
  • The added tests are present in src/plugins/note.rs and should pass in an environment with required system libraries installed.

Codex Task

@multiplex55 multiplex55 merged commit 7a6a438 into master Feb 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant