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:
Paddy committed 2022-01-08 15:42:09 +00:00
1 parent 88569f8a40
commit b4d5bdd0b6
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 RaPlaChangesDB {
const pool = mariadb.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.RAPLACHANGES_DATABASE,
connectionLimit: 5
});
export function getConnection() {
return pool;
}
}
@@ -1,23 +1,13 @@
import * as dotenv from 'dotenv';
import {Event} from './Event.interface';
import {Change} from './Change.interface';
import {RaPlaChangesDB} from '../DHBWRaPlaChanges.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.RAPLACHANGES_DATABASE,
connectionLimit: 5
});
export const getChanges = async (course: string, week: string): Promise<Event[]> => {
let conn;
let conn = RaPlaChangesDB.getConnection();
try {
conn = await pool.getConnection();
let relevantEventsRows = await conn.query('SELECT DISTINCT(entry_id) FROM rapla_changes WHERE new_start > ? AND new_start < DATE_ADD(?, INTERVAL 7 DAY)', [week, week]);
let relevantEventIds: string[] = [];
@@ -78,18 +68,12 @@ export const getChanges = async (course: string, week: string): Promise<Event[]>
return Array.from(eventsMap.values()) as Event[];
} catch (err) {
throw err;
} finally {
if (conn) {
conn.end();
}
}
};
export const getEventById = async (course: string, id: string): Promise<Event> => {
let conn;
let conn = RaPlaChangesDB.getConnection();
try {
conn = await pool.getConnection();
let rows = await conn.query('SELECT c.change_id, c.entry_id, c.change_timestamp, c.isDeleted, c.new_summary, c.new_description, c.new_start, c.new_last_modified, c.new_end, c.new_created, c.new_location, c.new_organizer, c.new_categories, e.uid FROM rapla_changes c LEFT OUTER JOIN rapla_entries e ON c.entry_id = e.entry_id WHERE e.uid = ? ORDER BY c.change_id', id);
let eventsMap = new Map();
@@ -139,9 +123,5 @@ export const getEventById = async (course: string, id: string): Promise<Event> =
return Array.from(eventsMap.values())[0];
} catch (err) {
throw err;
} finally {
if (conn) {
conn.end();
}
}
};