feat: add hybrid mode and other improvements#5
Conversation
Review or Edit in CodeSandboxOpen the branch in Web Editor • VS Code • Insiders |
✅ Deploy Preview for hyperdb canceled.
|
|
Warning Review limit reached
More reviews will be available in 57 minutes and 20 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (10)
📝 WalkthroughWalkthroughIntroduces ChangesHybridDB Runtime and Supporting Infrastructure
Sequence Diagram(s)sequenceDiagram
participant useAsyncSelector
participant runSelectorMaybeAsync
participant HybridDB
participant hybridIntervalScan
participant CacheDB
participant PrimaryDB
rect rgba(100, 149, 237, 0.5)
note over useAsyncSelector,runSelectorMaybeAsync: Synchronous-first selector path
useAsyncSelector->>runSelectorMaybeAsync: run selector generator
runSelectorMaybeAsync->>HybridDB: SelectRangeCmd → intervalScan
HybridDB->>hybridIntervalScan: primary, cache, cachedIntervals, selectEvent
end
alt cache hit (in-mem)
hybridIntervalScan->>CacheDB: intervalScan
CacheDB-->>hybridIntervalScan: rows (source = "in-mem")
hybridIntervalScan-->>runSelectorMaybeAsync: rows (sync)
runSelectorMaybeAsync-->>useAsyncSelector: result (sync, applied same tick)
else cache miss (persist)
hybridIntervalScan->>PrimaryDB: intervalScan
PrimaryDB-->>hybridIntervalScan: rows (source = "persist")
hybridIntervalScan->>CacheDB: upsert rows + merge coverage
hybridIntervalScan-->>runSelectorMaybeAsync: rows (may be Promise)
runSelectorMaybeAsync-->>useAsyncSelector: Promise
useAsyncSelector->>useAsyncSelector: then/catch/finally → setResult
end
Estimated code review effort🎯 5 (Critical) | ⏱️ ~120 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
There was a problem hiding this comment.
Actionable comments posted: 6
🤖 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.
Inline comments:
In `@packages/hyperdb-devtool/src/components.test.tsx`:
- Around line 181-252: The tab-persistence test in HyperDBDevtoolsPanel can leak
mounted DOM state if an assertion fails before teardown. Update the test around
createRoot, root.render, and the host element so cleanup always runs by wrapping
the render/assertions in a try/finally or equivalent shared teardown. Ensure
root.unmount() and host.remove() are guaranteed even when the selections in
getDetailTab or getButtonContaining fail.
In `@packages/hyperdb/src/hyperdb/runtime/hybrid-db-intervals.test.ts`:
- Line 1: The test file formatting is out of sync with Prettier. Run Prettier on
the hybrid-db-intervals test and commit the formatting-only changes, keeping the
existing Vitest imports and test structure intact.
In `@packages/hyperdb/src/hyperdb/runtime/hybrid-db-intervals.ts`:
- Line 1: This file only needs formatting cleanup to satisfy the CI prettier
check. Run the formatter on the hybrid-db-intervals.ts module and ensure the
import statement for DBCmd matches the project’s Prettier style; no functional
changes are needed.
In `@packages/hyperdb/src/hyperdb/runtime/hybrid-db.ts`:
- Around line 1-3: This file is failing the formatting check, so update the
imports in hybrid-db.ts to match Prettier’s expected style. Reformat the
existing import statements from the module paths under ../commands/async,
../core/contracts, and ../core/primitives, then run the formatter so the file
matches the project’s standard output.
- Around line 122-144: The write-through paths in hybrid-db’s insert, upsert,
and delete currently commit the primary before the cache, leaving a failure
window where the primary succeeds but the cache can still serve stale data.
Update the HybridDB mutation flow so primary and cache are coordinated
transactionally, or ensure a cache invalidation/rebuild happens before surfacing
any cache-write error. Apply the same fix to the matching mutation methods
referenced by the same pattern elsewhere in HybridDB.
In `@packages/hyperdb/src/react/hooks.test.ts`:
- Line 290: The test still asserts the old runSelectorAsync mock, but the hook
wiring now uses runSelectorMaybeAsync instead. Update this expectation in
hooks.test.ts to assert the behavior of runSelectorMaybeAsync in the relevant
test case, or remove the stale assertion if it is no longer needed, using the
runSelectorMaybeAsync and runSelectorAsync mock names to locate the affected
test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 14921998-84ad-4de1-9f88-86ba66f9b757
📒 Files selected for processing (27)
README.mdTODO.mdpackages/hyperdb-demo/src/BenchmarkApp.tsxpackages/hyperdb-demo/src/store-mode.tspackages/hyperdb-demo/src/stores.tspackages/hyperdb-devtool/README.mdpackages/hyperdb-devtool/src/components.test.tsxpackages/hyperdb-devtool/src/components.tsxpackages/hyperdb-doc/src/content/docs/integrations/devtools.mdpackages/hyperdb-doc/src/content/docs/integrations/react.mdpackages/hyperdb-doc/src/content/docs/runtime/db.mdpackages/hyperdb/README.mdpackages/hyperdb/src/hyperdb/commands/runner.tspackages/hyperdb/src/hyperdb/commands/selector/selector.tspackages/hyperdb/src/hyperdb/core/executor.test.tspackages/hyperdb/src/hyperdb/core/executor.tspackages/hyperdb/src/hyperdb/core/tracer.tspackages/hyperdb/src/hyperdb/index.tspackages/hyperdb/src/hyperdb/runtime/hybrid-db-intervals.test.tspackages/hyperdb/src/hyperdb/runtime/hybrid-db-intervals.tspackages/hyperdb/src/hyperdb/runtime/hybrid-db.test.tspackages/hyperdb/src/hyperdb/runtime/hybrid-db.tspackages/hyperdb/src/hyperdb/runtime/subscribable-db.tspackages/hyperdb/src/hyperdb/tracing/context.tspackages/hyperdb/src/hyperdb/tracing/store.tspackages/hyperdb/src/react/hooks.test.tspackages/hyperdb/src/react/hooks.ts
|
|
||
| expect(selector).toHaveBeenCalledWith({ projectId: "project-1" }); | ||
| expect(mocks.runSelectorMaybeAsync).toHaveBeenCalledTimes(1); | ||
| expect(mocks.runSelectorAsync).not.toHaveBeenCalled(); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Remove the stale runSelectorAsync assertion.
Line 100 wires runSelectorMaybeAsync, so this assertion either fails if the old mock was removed or verifies an unused mock if retained. Assert runSelectorMaybeAsync behavior here or delete this line.
🤖 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 `@packages/hyperdb/src/react/hooks.test.ts` at line 290, The test still asserts
the old runSelectorAsync mock, but the hook wiring now uses
runSelectorMaybeAsync instead. Update this expectation in hooks.test.ts to
assert the behavior of runSelectorMaybeAsync in the relevant test case, or
remove the stale assertion if it is no longer needed, using the
runSelectorMaybeAsync and runSelectorAsync mock names to locate the affected
test.
Summary by CodeRabbit
New Features
Bug Fixes