fix(sqlite): repair search docs FTS maintenance#1588
Conversation
📝 WalkthroughWalkthrough
ChangesFTS5 Schema Management Refactor
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/main/presenter/sqlitePresenter/tables/deepchatSearchDocuments.ts (1)
75-81: ⚡ Quick win
isFtsAvailable()re-queriessqlite_masteron every search — consider caching the ready state.After
ensureFtsTable()completes successfully,ftsUnavailableisfalsebutisFtsAvailable()still callshasCompatibleFtsTable(), which issues asqlite_masterread on everysearchFts()invocation. TheftsUnavailablefast-exit only fires on the error path.The simplest fix is to introduce a separate positive flag:
♻️ Proposed refactor
- private ftsUnavailable = false + private ftsUnavailable = false + private ftsReady = false isFtsAvailable(): boolean { - if (this.ftsUnavailable) { - return false - } - - return this.hasCompatibleFtsTable() + if (this.ftsReady) return true + if (this.ftsUnavailable) return false + return this.hasCompatibleFtsTable() }// In ensureFtsTable(), after the transaction: - this.ftsUnavailable = false + this.ftsUnavailable = false + this.ftsReady = trueThe
hasCompatibleFtsTable()guard remains useful for the first call beforecreateTable()runs, and the positiveftsReadyflag short-circuits all subsequent hot-path calls.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/presenter/sqlitePresenter/tables/deepchatSearchDocuments.ts` around lines 75 - 81, isFtsAvailable() currently re-queries sqlite_master on every search because after ensureFtsTable() succeeds it still calls hasCompatibleFtsTable(); add a positive cached flag (e.g., ftsReady) that ensureFtsTable() sets to true on success and have isFtsAvailable() return false if ftsUnavailable is true, true if ftsReady is true, otherwise fall back to hasCompatibleFtsTable(); update searchFts() hot path to rely on isFtsAvailable() so subsequent searches short-circuit without repeated sqlite_master reads.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/main/presenter/sqlitePresenter/tables/deepchatSearchDocuments.ts`:
- Around line 75-81: isFtsAvailable() currently re-queries sqlite_master on
every search because after ensureFtsTable() succeeds it still calls
hasCompatibleFtsTable(); add a positive cached flag (e.g., ftsReady) that
ensureFtsTable() sets to true on success and have isFtsAvailable() return false
if ftsUnavailable is true, true if ftsReady is true, otherwise fall back to
hasCompatibleFtsTable(); update searchFts() hot path to rely on isFtsAvailable()
so subsequent searches short-circuit without repeated sqlite_master reads.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 8aece51f-cafe-4677-b985-a2e5628b0429
📒 Files selected for processing (1)
src/main/presenter/sqlitePresenter/tables/deepchatSearchDocuments.ts
repair search docs FTS maintenance
fix
Error occurred in handler for 'deepchat:route:invoke': SqliteError: database disk image is malformedSummary by CodeRabbit