mirror of
https://github.com/Fabio286/antares.git
synced 2025-06-05 21:59:22 +02:00
perf: improved performance getting database structure
This commit is contained in:
@ -36,21 +36,23 @@ export class MySQLClient extends AntaresCore {
|
|||||||
*/
|
*/
|
||||||
async getStructure () {
|
async getStructure () {
|
||||||
const { rows: databases } = await this.raw('SHOW DATABASES');
|
const { rows: databases } = await this.raw('SHOW DATABASES');
|
||||||
// TODO: SHOW TABLE STATUS FROM `{DATABASE_NAME}`;
|
|
||||||
|
|
||||||
const { rows: tables } = await this
|
|
||||||
.select('*')
|
|
||||||
.schema('information_schema')
|
|
||||||
.from('TABLES')
|
|
||||||
.orderBy({ TABLE_SCHEMA: 'ASC', TABLE_NAME: 'ASC' })
|
|
||||||
.run();
|
|
||||||
|
|
||||||
const { rows: functions } = await this.raw('SHOW FUNCTION STATUS');
|
const { rows: functions } = await this.raw('SHOW FUNCTION STATUS');
|
||||||
const { rows: procedures } = await this.raw('SHOW PROCEDURE STATUS');
|
const { rows: procedures } = await this.raw('SHOW PROCEDURE STATUS');
|
||||||
const { rows: schedulers } = await this.raw('SELECT *, EVENT_SCHEMA AS `Db`, EVENT_NAME AS `Name` FROM information_schema.`EVENTS`');
|
const { rows: schedulers } = await this.raw('SELECT *, EVENT_SCHEMA AS `Db`, EVENT_NAME AS `Name` FROM information_schema.`EVENTS`');
|
||||||
|
|
||||||
|
const tablesArr = [];
|
||||||
const triggersArr = [];
|
const triggersArr = [];
|
||||||
|
|
||||||
for (const db of databases) {
|
for (const db of databases) {
|
||||||
|
let { rows: tables } = await this.raw(`SHOW TABLE STATUS FROM \`${db.Database}\``);
|
||||||
|
if (tables.length) {
|
||||||
|
tables = tables.map(table => {
|
||||||
|
table.Db = db.Database;
|
||||||
|
return table;
|
||||||
|
});
|
||||||
|
tablesArr.push(...tables);
|
||||||
|
}
|
||||||
|
|
||||||
let { rows: triggers } = await this.raw(`SHOW TRIGGERS FROM \`${db.Database}\``);
|
let { rows: triggers } = await this.raw(`SHOW TRIGGERS FROM \`${db.Database}\``);
|
||||||
if (triggers.length) {
|
if (triggers.length) {
|
||||||
triggers = triggers.map(trigger => {
|
triggers = triggers.map(trigger => {
|
||||||
@ -63,9 +65,9 @@ export class MySQLClient extends AntaresCore {
|
|||||||
|
|
||||||
return databases.map(db => {
|
return databases.map(db => {
|
||||||
// TABLES
|
// TABLES
|
||||||
const remappedTables = tables.filter(table => table.TABLE_SCHEMA === db.Database).map(table => {
|
const remappedTables = tablesArr.filter(table => table.Db === db.Database).map(table => {
|
||||||
let tableType;
|
let tableType;
|
||||||
switch (table.TABLE_TYPE) {
|
switch (table.Comment) {
|
||||||
case 'VIEW':
|
case 'VIEW':
|
||||||
tableType = 'view';
|
tableType = 'view';
|
||||||
break;
|
break;
|
||||||
@ -75,16 +77,16 @@ export class MySQLClient extends AntaresCore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: table.TABLE_NAME,
|
name: table.Name,
|
||||||
type: tableType,
|
type: tableType,
|
||||||
rows: table.TABLE_ROWS,
|
rows: table.Rows,
|
||||||
created: table.CREATE_TIME,
|
created: table.Create_time,
|
||||||
updated: table.UPDATE_TIME,
|
updated: table.Update_time,
|
||||||
engine: table.ENGINE,
|
engine: table.Engine,
|
||||||
comment: table.TABLE_COMMENT,
|
comment: table.Comment,
|
||||||
size: table.DATA_LENGTH + table.INDEX_LENGTH,
|
size: table.Data_length + table.Index_length,
|
||||||
autoIncrement: table.AUTO_INCREMENT,
|
autoIncrement: table.Auto_increment,
|
||||||
collation: table.TABLE_COLLATION
|
collation: table.Collation
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -212,6 +212,7 @@ body {
|
|||||||
|
|
||||||
.input-group .input-group-addon {
|
.input-group .input-group-addon {
|
||||||
border-color: #3f3f3f;
|
border-color: #3f3f3f;
|
||||||
|
z-index: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.menu {
|
.menu {
|
||||||
@ -225,7 +226,7 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.accordion-body {
|
.accordion-body {
|
||||||
max-height: 500rem !important;
|
max-height: 5000rem !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn.loading {
|
.btn.loading {
|
||||||
|
Reference in New Issue
Block a user