mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 14:38:50 +00:00
feat(logger): add logStorage size limit
Prevent excessive memory use when people use ui in production.
This commit is contained in:
1 parent
f05d375c14
commit
0a8b15a9b5
2 files changed
+12
-6
No files matched your search
+8
-4
@@ -3,7 +3,11 @@ import { typeCast } from './utils/typeCast';
|
||||
export const mysql_connection_string = GetConvar('mysql_connection_string', '');
|
||||
export let mysql_ui = GetConvar('mysql_ui', 'false') === 'true';
|
||||
export let mysql_slow_query_warning = GetConvarInt('mysql_slow_query_warning', 200);
|
||||
export let mysql_debug: boolean | string[];
|
||||
export let mysql_debug: boolean | string[] = false;
|
||||
|
||||
// max array size of individual resource query logs
|
||||
// prevent excessive memory use when people use debug/ui in production
|
||||
export let mysql_log_size = 0;
|
||||
|
||||
export function setDebug() {
|
||||
mysql_ui = GetConvar('mysql_ui', 'false') === 'true';
|
||||
@@ -15,6 +19,8 @@ export function setDebug() {
|
||||
} catch (e) {
|
||||
mysql_debug = true;
|
||||
}
|
||||
|
||||
mysql_log_size = mysql_debug ? 10000 : GetConvarInt('mysql_log_size', 100);
|
||||
}
|
||||
|
||||
export const mysql_transaction_isolation_level = (() => {
|
||||
@@ -87,9 +93,7 @@ export const connectionOptions = (() => {
|
||||
try {
|
||||
options[key] = JSON.parse(value);
|
||||
} catch (err) {
|
||||
console.log(
|
||||
`^3Failed to parse property ${key} in configuration (${err})!^0`
|
||||
)
|
||||
console.log(`^3Failed to parse property ${key} in configuration (${err})!^0`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -1,5 +1,5 @@
|
||||
import { PoolConnection, RowDataPacket } from 'mysql2/promise';
|
||||
import { mysql_debug, mysql_slow_query_warning, mysql_ui } from '../config';
|
||||
import { mysql_debug, mysql_log_size, mysql_slow_query_warning, mysql_ui } from '../config';
|
||||
import type { CFXCallback, CFXParameters } from '../types';
|
||||
import { dbVersion } from '../database';
|
||||
|
||||
@@ -109,7 +109,9 @@ export const logQuery = (
|
||||
|
||||
if (!mysql_ui) return;
|
||||
|
||||
if (logStorage[invokingResource] === undefined) logStorage[invokingResource] = [];
|
||||
if (!logStorage[invokingResource]) logStorage[invokingResource] = [];
|
||||
else if (logStorage[invokingResource].length > mysql_log_size) logStorage[invokingResource].splice(0, 1);
|
||||
|
||||
logStorage[invokingResource].push({
|
||||
query,
|
||||
executionTime,
|
||||
|
||||
Reference in new issue
Block a user