API-36: 🚑 Fixing critical issue with the amount of sql connections (!15)
Jenkins Production Deployment
Jenkins Production Deployment
Co-authored-by: Patrick Mueller <patrick@mueller-patrick.tech> Reviewed-on: #15 Co-authored-by: Patrick Müller <patrick@plutodev.de> Co-committed-by: Patrick Müller <patrick@plutodev.de>
This commit was merged in pull request #15.
This commit is contained in:
@@ -1,24 +1,9 @@
|
||||
import * as dotenv from 'dotenv';
|
||||
import {Event} from './Event.interface';
|
||||
import {PartyPlanerDB} from '../PartyPlaner.db';
|
||||
|
||||
dotenv.config();
|
||||
|
||||
const mariadb = require('mariadb');
|
||||
const prod_pool = mariadb.createPool({
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.PARTYPLANER_PROD_DATABASE,
|
||||
connectionLimit: 5
|
||||
});
|
||||
const dev_pool = mariadb.createPool({
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.PARTYPLANER_DEV_DATABASE,
|
||||
connectionLimit: 5
|
||||
});
|
||||
|
||||
/**
|
||||
* Returns all events of the given user
|
||||
* @param useDev If the dev or prod database should be used
|
||||
@@ -26,14 +11,8 @@ const dev_pool = mariadb.createPool({
|
||||
* @return Event[] A list of events
|
||||
*/
|
||||
export const getEventData = async (useDev: boolean, userId: string): Promise<Event[]> => {
|
||||
let conn;
|
||||
let conn = PartyPlanerDB.getConnection(useDev);
|
||||
try {
|
||||
if (useDev) {
|
||||
conn = await dev_pool.getConnection();
|
||||
} else {
|
||||
conn = await prod_pool.getConnection();
|
||||
}
|
||||
|
||||
let eventRows = await conn.query('SELECT event_id, name, description, takes_place_date, registration_until_date, max_participants FROM events WHERE creator_id = ?', userId);
|
||||
|
||||
let eventsMap = new Map<string, Event>();
|
||||
@@ -90,9 +69,5 @@ export const getEventData = async (useDev: boolean, userId: string): Promise<Eve
|
||||
return eventsList;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
} finally {
|
||||
if (conn) {
|
||||
conn.end();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user