API-36: 🚑 Fixing critical issue with the amount of sql connections (!15)
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:
2022-01-08 15:42:09 +00:00
parent 88569f8a40
commit b4d5bdd0b6
22 changed files with 159 additions and 580 deletions
@@ -0,0 +1,19 @@
import * as dotenv from 'dotenv';
const mariadb = require('mariadb');
dotenv.config();
export namespace HighlightMarkerDB {
const pool = mariadb.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.BETTERZON_DATABASE,
connectionLimit: 5
});
export function getConnection() {
return pool;
}
}
@@ -1,25 +1,15 @@
import * as dotenv from 'dotenv';
import {HighlightMarkerDB} from '../HighlightMarker.db';
dotenv.config();
const mariadb = require('mariadb');
const pool = mariadb.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.TWITCH_HIGHLIGHTS_DATABASE,
connectionLimit: 5
});
/**
* Creates a new highlight entry in SQL
* @param req_body The request body
*/
export const createHighlightEntry = async (req_body: any) => {
let conn;
let conn = HighlightMarkerDB.getConnection();
try {
conn = await pool.getConnection();
const streamers = await conn.query('SELECT streamer_id FROM streamers WHERE username = ?', req_body.streamer);
let streamer_id: number = -1;
@@ -34,9 +24,5 @@ export const createHighlightEntry = async (req_body: any) => {
const rows = await conn.query('INSERT INTO highlights (streamer_id, stream_id, description, stream_timestamp, issuing_user, game) VALUES (?, ?, ?, ?, ?, ?)', params);
} catch (err) {
throw err;
} finally {
if (conn) {
conn.end();
}
}
};