refactor: consolidate the parse+schema+build query idiom#74
Conversation
Several daemon search sites repeated the same three-step dance: parse_query(str) -> MxrSchema::build() -> QueryBuilder::new(&schema).build(&ast). If the query-compilation path ever changed, every caller had to change with it. Add `mxr_search::CompiledQuery` (parses once, holds the schema, builds a fresh Tantivy query per call — paging loops consume the query each page) plus a `build_query(&str)` convenience for single-use sites. Switch the batch-mutation address loop to CompiledQuery (preserving its parse-once / schema-once behaviour) and archive_ask to build_query. A golden test asserts the helper produces byte-identical query output to the manual path, so this is a pure consolidation.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR introduces a query compilation API that separates parsing from query building, enabling pagination without repeated schema construction. ChangesQuery Compilation API and Handler Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 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)
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 |
What
Consolidates the repeated
parse_query→MxrSchema::build→QueryBuilder::new(&schema).build(&ast)idiom intomxr_search::CompiledQuery+ abuild_query(&str)convenience. Audit backlog item P2 #20. Offmain; behavior-preserving.Why
Several daemon search sites (batch-mutation address loop, archive_ask) repeated the same three-step query compilation. Any change to the path meant touching every caller.
How
CompiledQuery::parse(query)parses once and captures the schema;build()yields a freshBox<dyn Query>per call (paging loops consume the query each page, so they need a fresh one without rebuilding the schema).build_query(&str)is the single-use convenience.mutations.rsbatch loop →CompiledQuery(preserves its parse-once/schema-once behaviour);archive_ask.rs→build_query.search_execute.rsis intentionally left alone — it works from a pre-parsedastwith optional account scoping (build_in_account), a different shape.Verification
build_query/CompiledQueryproduce byte-identical ({:?}) query output to the manual path across several queries, plus parse-error propagation.mxr-search40 + daemon consumer tests pass; clippy + fmt clean.Generated with Claude Code
Summary by cubic
Consolidates the repeated query parse+schema+build path into
mxr_search::CompiledQueryand abuild_query(&str)helper. This removes duplication and keeps paging loops efficient while preserving behavior.CompiledQuery::parse(query)(parses once, holdsMxrSchema);build()returns a freshBox<dyn Query>per call.build_query(&str)for single-use callers; re-export both frommxr_search.mutations.rsusesCompiledQuery;archive_ask.rsusesbuild_query. Leavesearch_execute.rsas-is (pre-parsed AST/account-scoped path).Written for commit 9ba92e1. Summary will update on new commits.
Summary by CodeRabbit