API-36: 🚑 Fixing critical issue with the amount of sql connections
This commit is contained in:
22 files changed
+159
-580
No files matched your search
@@ -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();
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in new issue
Block a user