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 {Friendship} from './Friendship.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 friends 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 Friendship[] A list of friends
|
||||
*/
|
||||
export const getFriendshipData = async (useDev: boolean, userId: string): Promise<Friendship[]> => {
|
||||
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 f.friendship_id, f.friend_id, u.first_name as friend_first_name, u.last_name as friend_last_name, u.username as friend_username FROM friendships f LEFT OUTER JOIN users u ON f.friend_id = u.user_id WHERE f.user_id = ?', userId);
|
||||
|
||||
let friends: Friendship[] = [];
|
||||
@@ -51,9 +30,5 @@ export const getFriendshipData = async (useDev: boolean, userId: string): Promis
|
||||
return friends;
|
||||
} catch (err) {
|
||||
throw err;
|
||||
} finally {
|
||||
if (conn) {
|
||||
conn.end();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user