Skip to content

feat(db): expose EvictionConfig and relax default to favor search UX#4

Merged
hitalin merged 1 commit intomainfrom
feat/eviction-config
Apr 28, 2026
Merged

feat(db): expose EvictionConfig and relax default to favor search UX#4
hitalin merged 1 commit intomainfrom
feat/eviction-config

Conversation

@hitalin
Copy link
Copy Markdown
Owner

@hitalin hitalin commented Apr 28, 2026

Summary

notes_cache の eviction 設定をアプリ側から指定できるよう EvictionConfig を公開し、デフォルトを「過去ノート検索」を阻害しない緩い値に変更する。

Why

#3 で導入した eviction (TTL 90 日 + per-account 50,000 件) は、ノートクライアントの差別化要素である「過去ノートをローカルキャッシュから一瞬で全文検索 (FTS5)」という UX を阻害していた。

ヘビーユーザーは数年分の過去ノートをキャッシュとして保持したいケースが多く、デフォルトで 90 日でカットされるのは不利益。一方、無制限だと長期使用で青天井に肥大化するため、暴走防止の hard cap だけは残しつつデフォルトを緩める設計にする。

Changes

新規 EvictionConfig (specta feature 対応)

pub struct EvictionConfig {
    pub per_account_limit: Option<i64>,  // None なら無制限
    pub ttl_days: Option<i64>,            // None なら無期限
}

impl Default for EvictionConfig {
    fn default() -> Self {
        Self {
            per_account_limit: Some(1_000_000),  // 実質暴走防止のみ
            ttl_days: None,                       // 期限なし
        }
    }
}

API 拡張

  • Database::open(path) — 後方互換性のため維持。EvictionConfig::default() で動作。
  • Database::open_with_eviction(path, config) — 新規。アプリ側がユーザー設定を渡す。
  • Database::cleanup_with_eviction(&config) — 新規。設定変更時に即時再 cleanup できる。
  • cleanup_cache_inner を統合・廃止。

None のフィールドは該当 DELETE をスキップする設計で、両方 None なら lock すら取らずに早期 return する。

Test plan

  • cargo test --lib db:: で 27 件 全 pass (新規 3 件: both-disabled no-op / TTL only / Default の検証)
  • cargo build --features specta 通過
  • 既存 6 件のテストを新 API に追従

Migration impact

  • CLI / daemon: Database::open(path) の挙動変更 (デフォルトが大幅に緩い側へ)。長期運用 DB がディスク食いになる可能性はあるが、暴走防止 cap 1M はあるので致命ではない。明示的に厳しい掃除をしたい利用者は open_with_eviction を呼ぶ。
  • notedeck: 続編 PR (notedeck#402) で open_with_eviction を呼び、ユーザー設定を cacheEditor ウィンドウから調整できるようにする予定。

Related

これまでデフォルトが TTL 90 日 + per-account 50,000 件のハードな掃除だった
ため、ノートクライアント (例: notedeck) の差別化要素である「過去ノートを
ローカルキャッシュから一瞬で全文検索」 という UX を阻害していた。

変更点:

- 新規 `EvictionConfig { per_account_limit: Option<i64>, ttl_days: Option<i64> }`
  を公開。`None` でその条件をスキップする設計。`#[cfg_attr(feature = "specta",
  derive(specta::Type))]` 付きでアプリ側 (notedeck) からも型化して呼べる。
- `Database::open(path)` は後方互換性のため残し、デフォルト動作を「ほぼ永続」
  に緩和:
  - `per_account_limit: Some(1_000_000)` (実質暴走防止のみ)
  - `ttl_days: None` (期限なし)
- 新規 `Database::open_with_eviction(path, EvictionConfig)` を追加。 アプリ側で
  ユーザー設定値を渡す経路。
- 新規 `Database::cleanup_with_eviction(&EvictionConfig)` を追加。 起動時の
  自動実行に加え、設定変更時に即時再 cleanup を行うためのフック。
- 旧 `cleanup_cache_inner` を `cleanup_with_eviction` に統合。

検索性を尊重するため CLI / daemon でもデフォルトでは「ほぼ永続」となる。
強い掃除が必要な利用者は明示的に `EvictionConfig` を渡す。

テスト:
- 既存 4 件を新 API に追従 (TTL only / cap only の組み合わせを明示)
- 新規 3 件追加: both disabled で no-op、TTL only で cap 無視、デフォルト値の検証

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@hitalin hitalin merged commit aeb6915 into main Apr 28, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant