mirror of
https://github.com/Fabio286/antares.git
synced 2025-02-16 11:41:25 +01:00
perf(MySQL): made some common errors related to corrupted tables non-blocking, closes #877
This commit is contained in:
parent
2f3f5de8d6
commit
9a0ad80bb5
@ -3,14 +3,25 @@ import mysql from 'mysql2/promise';
|
|||||||
import * as pg from 'pg';
|
import * as pg from 'pg';
|
||||||
import SSH2Promise = require('@fabio286/ssh2-promise');
|
import SSH2Promise = require('@fabio286/ssh2-promise');
|
||||||
|
|
||||||
const queryLogger = ({ sql, cUid }: {sql: string; cUid: string}) => {
|
export type LoggerLevel = 'query' | 'error'
|
||||||
// Remove comments, newlines and multiple spaces
|
|
||||||
const escapedSql = sql.replace(/(\/\*(.|[\r\n])*?\*\/)|(--(.*|[\r\n]))/gm, '').replace(/\s\s+/g, ' ');
|
const ipcLogger = ({ content, cUid, level }: {content: string; cUid: string; level: LoggerLevel}) => {
|
||||||
if (process.type !== undefined) {
|
if (level === 'error') {
|
||||||
const mainWindow = require('electron').webContents.fromId(1);
|
if (process.type !== undefined) {
|
||||||
mainWindow.send('query-log', { cUid, sql: escapedSql, date: new Date() });
|
const mainWindow = require('electron').webContents.fromId(1);
|
||||||
|
mainWindow.send('non-blocking-exception', { cUid, message: content, date: new Date() });
|
||||||
|
}
|
||||||
|
if (process.env.NODE_ENV === 'development' && process.type === 'browser') console.log(content);
|
||||||
|
}
|
||||||
|
else if (level === 'query') {
|
||||||
|
// Remove comments, newlines and multiple spaces
|
||||||
|
const escapedSql = content.replace(/(\/\*(.|[\r\n])*?\*\/)|(--(.*|[\r\n]))/gm, '').replace(/\s\s+/g, ' ');
|
||||||
|
if (process.type !== undefined) {
|
||||||
|
const mainWindow = require('electron').webContents.fromId(1);
|
||||||
|
mainWindow.send('query-log', { cUid, sql: escapedSql, date: new Date() });
|
||||||
|
}
|
||||||
|
if (process.env.NODE_ENV === 'development' && process.type === 'browser') console.log(escapedSql);
|
||||||
}
|
}
|
||||||
if (process.env.NODE_ENV === 'development' && process.type === 'browser') console.log(escapedSql);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -22,7 +33,7 @@ export abstract class BaseClient {
|
|||||||
protected _params: mysql.ConnectionOptions | pg.ClientConfig | { databasePath: string; readonly: boolean};
|
protected _params: mysql.ConnectionOptions | pg.ClientConfig | { databasePath: string; readonly: boolean};
|
||||||
protected _poolSize: number;
|
protected _poolSize: number;
|
||||||
protected _ssh?: SSH2Promise;
|
protected _ssh?: SSH2Promise;
|
||||||
protected _logger: (args: {sql: string; cUid: string}) => void;
|
protected _logger: (args: {content: string; cUid: string; level: LoggerLevel}) => void;
|
||||||
protected _queryDefaults: antares.QueryBuilderObject;
|
protected _queryDefaults: antares.QueryBuilderObject;
|
||||||
protected _query: antares.QueryBuilderObject;
|
protected _query: antares.QueryBuilderObject;
|
||||||
|
|
||||||
@ -31,7 +42,7 @@ export abstract class BaseClient {
|
|||||||
this._cUid = args.uid;
|
this._cUid = args.uid;
|
||||||
this._params = args.params;
|
this._params = args.params;
|
||||||
this._poolSize = args.poolSize || undefined;
|
this._poolSize = args.poolSize || undefined;
|
||||||
this._logger = args.logger || queryLogger;
|
this._logger = args.logger || ipcLogger;
|
||||||
|
|
||||||
this._queryDefaults = {
|
this._queryDefaults = {
|
||||||
schema: '',
|
schema: '',
|
||||||
|
@ -1024,7 +1024,7 @@ export class FirebirdSQLClient extends BaseClient {
|
|||||||
alias: string;
|
alias: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
this._logger({ cUid: this._cUid, sql });
|
this._logger({ cUid: this._cUid, content: sql, level: 'query' });
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
nest: false,
|
nest: false,
|
||||||
|
@ -354,10 +354,21 @@ export class MySQLClient extends BaseClient {
|
|||||||
if (this._params.schema)
|
if (this._params.schema)
|
||||||
filteredDatabases = filteredDatabases.filter(db => db.Database === this._params.schema);
|
filteredDatabases = filteredDatabases.filter(db => db.Database === this._params.schema);
|
||||||
|
|
||||||
const { rows: functions } = await this.raw('SHOW FUNCTION STATUS');
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
const { rows: procedures } = await this.raw('SHOW PROCEDURE STATUS');
|
let functions: any[] = [];
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
let procedures: any[] = [];
|
||||||
let schedulers: any[] = [];
|
let schedulers: any[] = [];
|
||||||
|
/* eslint-enable @typescript-eslint/no-explicit-any */
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { rows: functionRows } = await this.raw('SHOW FUNCTION STATUS');
|
||||||
|
const { rows: procedureRows } = await this.raw('SHOW PROCEDURE STATUS');
|
||||||
|
functions = functionRows;
|
||||||
|
procedures = procedureRows;
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
this._logger({ content: err.sqlMessage, cUid: this._cUid, level: 'error' });
|
||||||
|
}
|
||||||
|
|
||||||
try { // Avoid exception with event_scheduler DISABLED with MariaDB 10
|
try { // Avoid exception with event_scheduler DISABLED with MariaDB 10
|
||||||
const { rows } = await this.raw('SELECT *, EVENT_SCHEMA AS `Db`, EVENT_NAME AS `Name` FROM information_schema.`EVENTS`');
|
const { rows } = await this.raw('SELECT *, EVENT_SCHEMA AS `Db`, EVENT_NAME AS `Name` FROM information_schema.`EVENTS`');
|
||||||
@ -1667,7 +1678,7 @@ export class MySQLClient extends BaseClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async raw<T = antares.QueryResult> (sql: string, args?: antares.QueryParams) {
|
async raw<T = antares.QueryResult> (sql: string, args?: antares.QueryParams) {
|
||||||
this._logger({ cUid: this._cUid, sql });
|
this._logger({ cUid: this._cUid, content: sql, level: 'query' });
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
nest: false,
|
nest: false,
|
||||||
|
@ -1645,7 +1645,7 @@ export class PostgreSQLClient extends BaseClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async raw<T = antares.QueryResult> (sql: string, args?: antares.QueryParams) {
|
async raw<T = antares.QueryResult> (sql: string, args?: antares.QueryParams) {
|
||||||
this._logger({ cUid: this._cUid, sql });
|
this._logger({ cUid: this._cUid, content: sql, level: 'query' });
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
nest: false,
|
nest: false,
|
||||||
|
@ -612,7 +612,7 @@ export class SQLiteClient extends BaseClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async raw<T = antares.QueryResult> (sql: string, args?: antares.QueryParams) {
|
async raw<T = antares.QueryResult> (sql: string, args?: antares.QueryParams) {
|
||||||
this._logger({ cUid: this._cUid, sql });// TODO: replace BLOB content with a placeholder
|
this._logger({ cUid: this._cUid, content: sql, level: 'query' });// TODO: replace BLOB content with a placeholder
|
||||||
|
|
||||||
args = {
|
args = {
|
||||||
nest: false,
|
nest: false,
|
||||||
|
@ -44,6 +44,15 @@ ipcRenderer.on('unhandled-exception', (event, error) => {
|
|||||||
date: new Date()
|
date: new Date()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
ipcRenderer.on('non-blocking-exception', (event, error) => {
|
||||||
|
useNotificationsStore().addNotification({ status: 'error', message: error.message });
|
||||||
|
useConsoleStore().putLog('debug', {
|
||||||
|
level: 'error',
|
||||||
|
process: 'main',
|
||||||
|
message: error.message,
|
||||||
|
date: new Date()
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// IPC query logs
|
// IPC query logs
|
||||||
ipcRenderer.on('query-log', (event, logRecord: QueryLog) => {
|
ipcRenderer.on('query-log', (event, logRecord: QueryLog) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user