feat(db): キャッシュ済みノートの述語注入スキャン API - #51
Merged
Merged
Conversation
判定ロジックが呼び出し側にしかない検索のための API を足す。この層は 「FTS で粗く絞って行を読み、述語に渡す」だけで、述語の意味論には関与しない。 notedeck のカラムクエリ (#783 Phase 3) が最初の利用者になる。 既存の search_cached_notes_advanced はユーザーの検索文字列 1 本を前提に しているため、別関数として追加した。 - fts_literals は AND 結合で FTS5 に押し込む。trigram が成立しない 3 文字未満は 落とす (押し込むと 0 件になり偽陰性を生む)。押し込めるものが無ければ全件走査 - max_scanned_rows で走査を打ち切り、継続カーソルを返す。巨大キャッシュでも 応答が返らなくならないようにする - カーソルは「最後に走査した行」を指す。最後にマッチした行を指すと、その間の マッチしない行を再開時に読み直すことになる - ORDER BY は created_at + note_id の複合。created_at が同値でも順序が定まり、 カーソル反復で取りこぼしと重複が出ない - 述語が None を返した行と、note_json として読めなかった行は per-note エラーと して件数に計上し、ノートは返さない - DB ロックはチャンク単位で取り直す。述語の評価はロックの外で行うので、重い 述語が他の DB 利用者を待たせない Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
This was referenced Aug 3, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
判定ロジックが呼び出し側にしかない検索のための API を追加します。この層は「FTS で粗く絞って行を読み、述語に渡す」だけで、述語の意味論には関与しません。
なぜ必要か
notedeck のカラムクエリ (notedeck-dev/notedeck#783) は、ユーザーが書いた式を独自の中間表現へコンパイルして評価します。その評価器は notedeck 側にあり、notecli が意味論を知る必要はありません。一方でキャッシュ DB を持っているのは notecli なので、「行を読む」ところだけをこちらが担当し、「判定する」ところは呼び出し側に任せる形にしました。
既存の
search_cached_notes_advancedはユーザーの検索文字列 1 本を前提にしているため、別関数として追加しています。設計
fts_literalsは AND 結合で FTS5 に押し込みます。trigram が成立しない 3 文字未満は落とします (押し込むと 0 件になり偽陰性を生むため)。押し込めるものが無ければ全件走査に落ちますmax_scanned_rowsで走査を打ち切り、継続カーソルを返します。巨大なキャッシュでも応答が返らなくならないようにするためですcreated_at+note_idの複合です。created_atが同値でも順序が定まるので、カーソル反復で取りこぼしと重複が出ませんNoneを返した行と、note_jsonとして読めなかった行 (スキーマ世代差・破損) は per-note エラーとして件数に計上し、ノートは返しませんテスト
10 件を追加しました。述語による絞り込み、FTS プリフィルタ、短いリテラルの無視、limit / 走査上限での打ち切り、カーソルからの再開で取りこぼしと重複が出ないこと、述語エラーと破損行の計上、アカウント境界を確認しています。
実装中に、
limitで打ち切ったときに継続カーソルを返せていないバグを見つけて直しました (チャンクの読み切り判定が優先されていました)。全 225 テスト通過、clippy クリーンです。
cargo fmt --checkがapi.rsで差分を出しますが、これは本 PR 以前からの状態なので触っていません。🤖 Generated with Claude Code