perf(mongodb): drop per-op ping, fix findKeys regex, unordered bulk#994
perf(mongodb): drop per-op ping, fix findKeys regex, unordered bulk#994SamTV12345 wants to merge 1 commit into
Conversation
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
Review Summary by QodoMongoDB and PostgreSQL driver performance optimizations
WalkthroughsDescription• Remove redundant per-operation MongoDB ping scheduling (clearInterval/setInterval pairs) • Fix MongoDB findKeys regex to properly escape metacharacters and anchor matches • Switch MongoDB bulk operations from ordered to unordered for server-side parallelization • Collapse PostgreSQL bulk upserts into single multi-row INSERT with ON CONFLICT • Add named prepared statements for PostgreSQL hottest queries (get, set, remove) • Tighten TypeScript types with UeberDoc document shape and Filter narrowing Diagramflowchart LR
A["MongoDB Operations"] -->|Remove schedulePing| B["Eliminate Timer Overhead"]
A -->|Fix findKeys Regex| C["Correct Pattern Matching"]
A -->|Unordered Bulk Ops| D["Enable Server Parallelization"]
E["PostgreSQL Operations"] -->|Multi-row Upsert| F["Reduce Round-trips"]
E -->|Named Prepared Statements| G["Cache Query Plans"]
H["Type Improvements"] -->|UeberDoc + Filter| I["Remove any Casts"]
File Changes1. databases/mongodb_db.ts
|
Code Review by Qodo
1. doBulk may never resolve
|
- Drop the per-operation schedulePing(). Every get/set/findKeys/remove/ doBulk did a clearInterval + setInterval pair. The mongodb driver already maintains its own server heartbeat, so this was two timer mutations per op for nothing. The interval field and clearPing/ schedulePing helpers are removed. - Fix findKeys regex. Previously stripped * instead of converting it to .*, and had no ^...$ anchor — producing unanchored substring matches that bypassed the _id index and could return false positives. Now escapes regex metacharacters and converts wildcards correctly. - doBulk uses initializeUnorderedBulkOp() instead of ordered — our bulk ops are keyed per-op so ordering is unnecessary, and unordered parallelizes server-side. - Tighten types: a UeberDoc document shape + Filter<UeberDoc> / Collection<UeberDoc> narrowing replace the any casts the changes above would otherwise have introduced. Split out of the old combined #994 to keep one backend per PR (AGENTS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Drop the per-operation schedulePing(). Every get/set/findKeys/remove/ doBulk did a clearInterval + setInterval pair. The mongodb driver already maintains its own server heartbeat, so this was two timer mutations per op for nothing. The interval field and clearPing/ schedulePing helpers are removed. - Fix findKeys regex. Previously stripped * instead of converting it to .*, and had no ^...$ anchor — producing unanchored substring matches that bypassed the _id index and could return false positives. Now escapes regex metacharacters and converts wildcards correctly. - doBulk uses initializeUnorderedBulkOp() instead of ordered — our bulk ops are keyed per-op so ordering is unnecessary, and unordered parallelizes server-side. - Tighten types: a UeberDoc document shape + Filter<UeberDoc> / Collection<UeberDoc> narrowing replace the any casts the changes above would otherwise have introduced. Split out of the old combined #994 to keep one backend per PR (AGENTS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- doBulk collapses N round-trips into one on the native-upsert path via a single multi-row INSERT ... VALUES ($1,$2),($3,$4),... ON CONFLICT DO UPDATE. The function-based fallback (old PG / CockroachDB without native upsert) is preserved for single-row and multi-row cases. - Named prepared statements on the three hottest single-row queries (get, set, remove) so PG parses + plans them once per connection. Split out of #994 to keep one backend per PR (AGENTS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Drop the per-operation schedulePing(). Every get/set/findKeys/remove/ doBulk did a clearInterval + setInterval pair. The mongodb driver already maintains its own server heartbeat, so this was two timer mutations per op for nothing. The interval field and clearPing/ schedulePing helpers are removed. - Fix findKeys regex. Previously stripped * instead of converting it to .*, and had no ^...$ anchor — producing unanchored substring matches that bypassed the _id index and could return false positives. Now escapes regex metacharacters and converts wildcards correctly. - doBulk uses initializeUnorderedBulkOp() instead of ordered — our bulk ops are keyed per-op so ordering is unnecessary, and unordered parallelizes server-side. - Tighten types: a UeberDoc document shape + Filter<UeberDoc> / Collection<UeberDoc> narrowing replace the any casts the changes above would otherwise have introduced. Split out of the old combined #994 to keep one backend per PR (AGENTS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- doBulk collapses N round-trips into one on the native-upsert path via a single multi-row INSERT ... VALUES ($1,$2),($3,$4),... ON CONFLICT DO UPDATE. The function-based fallback (old PG / CockroachDB without native upsert) is preserved for single-row and multi-row cases. - Named prepared statements on the three hottest single-row queries (get, set, remove) so PG parses + plans them once per connection. Split out of #994 to keep one backend per PR (AGENTS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
perf(mongodb): MongoDB driver optimizations
Touches
databases/mongodb_db.tsonly. Split out of the old combined MongoDB+PostgreSQL PR so each backend gets its own PR perAGENTS.md("one backend per PR"). The PostgreSQL half is now #997. Themongodb_db.tsdiff here is unchanged from the original combined PR.schedulePing(). Everyget/set/findKeys/remove/doBulkdid aclearInterval+setIntervalpair. The mongodb driver already maintains its own server heartbeat, so this was two timer mutations per op for nothing. Theintervalfield andclearPing/schedulePinghelpers are removed.findKeysregex. Previously stripped*instead of converting it to.*, and had no^…$anchor — producing unanchored substring matches that bypassed the_idindex and could return false positives. Now escapes regex metacharacters and converts wildcards correctly.doBulkusesinitializeUnorderedBulkOp()instead of ordered — our bulk ops are keyed per-op so ordering is unnecessary, and unordered parallelizes server-side.UeberDocdocument shape +Filter<UeberDoc>/Collection<UeberDoc>narrowing replace theanycasts the changes above would otherwise have introduced.🤖 Generated with Claude Code