perf: optimize backend auth performance (#25)#28
Conversation
|
@kanak-bansal is attempting to deploy a commit to the Shiv Raj Singh's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
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 optimizes backend authentication performance by enabling SMTP connection pooling, sending welcome emails asynchronously after the registration response, removing debug logging and adding ChangesAuthentication and Startup Performance Changes
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant AuthController
participant Nodemailer
participant Server
participant VectorStore
Client->>AuthController: register request
AuthController->>Client: success response (immediate)
AuthController->>Nodemailer: sendMail(welcome email, async)
Nodemailer-->>AuthController: success/error (logged)
Server->>Server: start listening
Server->>VectorStore: initVectorStore() (async)
VectorStore-->>Server: resolve/reject (logged)
Related issues: Suggested labels: performance, backend Suggested reviewers: imuniqueshiv Poem A rabbit hops through server code, 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
imuniqueshiv
left a comment
There was a problem hiding this comment.
@kanak-bansal Thank you for your contribution and the performance improvements you've implemented. I appreciate the effort you've put into optimizing the authentication flow. 🚀
While reviewing the changes, I noticed one issue in the register() controller that needs to be fixed before this PR can be merged.
Registration Response Logic
The current implementation sends the response twice:
res.json(...);
return res.json(...);This can result in:
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
Additionally, the asynchronous transporter.sendMail(...).catch(...) call is placed after the return statement, which makes it unreachable and therefore it will never execute.
Because of this:
- The welcome email is still being sent synchronously (
await transporter.sendMail(...)). - The intended performance optimization is not actually taking effect.
Please update the logic so that:
- Only one response is returned.
- The welcome email is sent asynchronously (without
await). - No unreachable code remains.
Once this is fixed, I'll review the updated changes again.
Thanks again for your contribution!
|
@kanak-bansal Any Updates? |
Closes #25
Summary
Optimized backend performance around authentication to reduce login/signup response time, without changing any auth logic, endpoints, or existing functionality.
Changes
controllers/authControllers.js- Register no longer waits on the welcome email before responding. The response returns immediately after the user is created; the email sends in the background with error handling.config/nodeMailer.js- Enabled SMTP connection pooling (pool: true,maxConnections: 5) to avoid a fresh TCP/TLS handshake on every email send.server.js- Server now starts accepting requests (app.listen) before the vector store finishes initializing, instead of blocking startup on it. Vector store still initializes, just in the background afterward.middleware/userAuth.js- Removed debugconsole.logstatements that ran on every authenticated request, and added.lean()to the user lookup for a lighter DB read.Testing
.lean()change.Summary by CodeRabbit