-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
feat: init version in postgres driver only if not set #11373
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughOptimizes PostgreSQL driver initialization by adding a guard condition that skips metadata fetches (version, current database, search/schema) when these values are already populated. Query runner resource management remains tied to the guarded block. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/driver/postgres/PostgresDriver.ts (1)
365-365: Consider documenting when metadata values would be pre-initialized.The guard condition assumes
version,database, orsearchSchemamight already be set beforeconnect()is called. From the constructor (lines 323-328), onlydatabaseandschemacan be initialized from connection options. It's unclear whenversionorsearchSchemawould be pre-set outside of a previousconnect()call.Consider adding a comment explaining the lazy initialization rationale:
+ // Lazy initialization: Skip metadata fetches if already populated + // (e.g., from constructor options or previous connect() call) if (!this.version || !this.database || !this.searchSchema) {This would help future maintainers understand the optimization's intent and the scenarios it handles.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/driver/postgres/PostgresDriver.ts(1 hunks)
🔇 Additional comments (1)
src/driver/postgres/PostgresDriver.ts (1)
365-381: Verify lazy initialization handles reconnection scenarios correctly.The guard condition and individual checks are logically sound. However, one important scenario needs verification:
Stale metadata on reconnection: The
disconnect()method clears connection pools but does NOT clear the cachedthis.version,this.database, andthis.searchSchemaproperties (lines 625-626 set pools to undefined but don't reset metadata). This means ifconnect()is called again on the same driver instance afterdisconnect(), the old cached metadata will be reused rather than fetched from the database. Verify whether this is the intended behavior for issue #11372, or ifdisconnect()should also clear these properties.The concern in the original review about null-checking at line 403 is not valid—
VersionUtils.isGreaterOrEqual()safely handles undefined values by returningfalse(seesrc/util/VersionUtils.ts:6-7).Verification checklist:
- Confirm whether reconnection after
disconnect()should fetch fresh metadata or reuse cached values- Add tests covering: (1) first
connect()fetches all metadata, (2) secondconnect()on same instance with nodisconnect()skips fetching, (3)connect()afterdisconnect()behavior- Consider whether
disconnect()should reset metadata properties to ensure fresh fetches on reconnection
G0maa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
@G0maa it was quite some time ago when I had that fresh in mind, right now I don't really remember what was the problem (maybe since I didn't request changes it wasn't that important). We could maybe offer some connection option |
G0maa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The general idea/approach looks good, I'm unsure if this would break things else where like @alumni said, waiting for maintainers' opinions.
Clarify that the Postgres version is set on the first connection attempt.
|
This can't break anything as we already set the version. It improves this, by setting the version only if it was not set before (so does it less forcefully). Feels like a good change. |
PR Code Suggestions ✨Latest suggestions up to 72b80b2
Previous suggestionsSuggestions up to commit 218e0b5
|
||||||||||||||||||
commit: |
gioboa
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👏
|
@hfhchan-plb Hold on, how does this even work? How would I use this if I wanted to avoid reading the version from the DB? I see it's relying on |
Description of change
Fixes #11372
Pull-Request Checklist
masterbranchnpm run formatto apply prettier formattingnpm run testpasses with this changeFixes #0000Summary by CodeRabbit