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 {SessionData} from './SessionData.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 active sessions 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 SessionData[] A list containing objects with the session data
|
||||
*/
|
||||
export const getSessionData = async (useDev: boolean, userId: string): Promise<SessionData[]> => {
|
||||
let conn;
|
||||
let conn = PartyPlanerDB.getConnection(useDev);
|
||||
try {
|
||||
if (useDev) {
|
||||
conn = await dev_pool.getConnection();
|
||||
} else {
|
||||
conn = await prod_pool.getConnection();
|
||||
}
|
||||
|
||||
let rows = await conn.query('SELECT session_id, type, last_login, last_ip FROM sessions WHERE user_id = ? AND valid_until > NOW()', userId);
|
||||
|
||||
let sessions: SessionData[] = [];
|
||||
@@ -50,9 +29,5 @@ export const getSessionData = async (useDev: boolean, userId: string): Promise<S
|
||||
return sessions;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
} finally {
|
||||
if (conn) {
|
||||
conn.end();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user