fix: implement persistent MongoDB connections and resolve race conditions
- Replace connect/disconnect pattern with persistent connection pool - Add explicit database initialization on server startup - Remove all dbDisconnect() calls from API endpoints to prevent race conditions - Fix MongoNotConnectedError when scheduler runs concurrently with API requests - Add connection pooling with proper MongoDB driver options - Add safety check for recipes array in favorites utility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { RequestHandler } from '@sveltejs/kit';
|
||||
import { PaymentSplit } from '../../../../models/PaymentSplit';
|
||||
import { Payment } from '../../../../models/Payment';
|
||||
import { dbConnect, dbDisconnect } from '../../../../utils/db';
|
||||
import { dbConnect } from '../../../../utils/db';
|
||||
import { error, json } from '@sveltejs/kit';
|
||||
|
||||
interface DebtSummary {
|
||||
@@ -105,6 +105,6 @@ export const GET: RequestHandler = async ({ locals }) => {
|
||||
console.error('Error calculating debt breakdown:', e);
|
||||
throw error(500, 'Failed to calculate debt breakdown');
|
||||
} finally {
|
||||
await dbDisconnect();
|
||||
// Connection will be reused
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user