mirror of
https://github.com/Fabio286/antares.git
synced 2025-02-17 04:00:48 +01:00
perf: approximate table total updated on table refresh
This commit is contained in:
parent
3abff36136
commit
dea378014d
@ -38,6 +38,16 @@ export default (connections) => {
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('get-table-count', async (event, params) => {
|
||||
try {
|
||||
const result = await connections[params.uid].getTableApproximateCount(params);
|
||||
return { status: 'success', response: result };
|
||||
}
|
||||
catch (err) {
|
||||
return { status: 'error', response: err.toString() };
|
||||
}
|
||||
});
|
||||
|
||||
ipcMain.handle('get-table-indexes', async (event, params) => {
|
||||
try {
|
||||
const result = await connections[params.uid].getTableIndexes(params);
|
||||
|
@ -424,6 +424,19 @@ export class MySQLClient extends AntaresCore {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} params
|
||||
* @param {String} params.schema
|
||||
* @param {String} params.table
|
||||
* @returns {Object} table row count
|
||||
* @memberof MySQLClient
|
||||
*/
|
||||
async getTableApproximateCount ({ schema, table }) {
|
||||
const { rows } = await this.raw(`SELECT table_rows "count" FROM information_schema.tables WHERE table_name = "${table}" AND table_schema = "${schema}"`);
|
||||
|
||||
return rows.length ? rows[0].count : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} params
|
||||
* @param {String} params.schema
|
||||
|
@ -293,6 +293,19 @@ export class PostgreSQLClient extends AntaresCore {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} params
|
||||
* @param {String} params.schema
|
||||
* @param {String} params.table
|
||||
* @returns {Object} table row count
|
||||
* @memberof PostgreSQLClient
|
||||
*/
|
||||
async getTableApproximateCount ({ schema, table }) {
|
||||
const { rows } = await this.raw(`SELECT reltuples AS count FROM pg_class WHERE relname = '${table}'`);
|
||||
|
||||
return rows.length ? rows[0].count : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Object} params
|
||||
* @param {String} params.schema
|
||||
|
@ -104,7 +104,7 @@ export default {
|
||||
return this.getWorkspace(this.selectedWorkspace);
|
||||
},
|
||||
customizations () {
|
||||
return this.workspace ? this.workspace.customizations : {};
|
||||
return this.workspace && this.workspace.customizations ? this.workspace.customizations : {};
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -112,8 +112,8 @@
|
||||
<div v-if="results.length && results[0].rows">
|
||||
{{ $t('word.results') }}: <b>{{ results[0].rows.length | localeString }}</b>
|
||||
</div>
|
||||
<div v-if="hasApproximately || (page > 1 && tableInfo.rows)">
|
||||
{{ $t('word.total') }}: <b>{{ tableInfo.rows | localeString }}</b> <small>({{ $t('word.approximately') }})</small>
|
||||
<div v-if="hasApproximately || (page > 1 && approximateCount)">
|
||||
{{ $t('word.total') }}: <b :title="$t('word.approximately')">≈ {{ approximateCount | localeString }}</b>
|
||||
</div>
|
||||
<div class="d-flex" :title="$t('word.schema')">
|
||||
<i class="mdi mdi-18px mdi-database mr-1" /><b>{{ schema }}</b>
|
||||
@ -175,7 +175,7 @@ export default {
|
||||
},
|
||||
filters: {
|
||||
localeString (val) {
|
||||
if (val)
|
||||
if (val !== null)
|
||||
return val.toLocaleString();
|
||||
}
|
||||
},
|
||||
@ -200,7 +200,8 @@ export default {
|
||||
refreshInterval: null,
|
||||
sortParams: {},
|
||||
page: 1,
|
||||
pageProxy: 1
|
||||
pageProxy: 1,
|
||||
approximateCount: 0
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@ -232,15 +233,15 @@ export default {
|
||||
hasApproximately () {
|
||||
return this.results.length &&
|
||||
this.results[0].rows &&
|
||||
this.tableInfo &&
|
||||
this.results[0].rows.length === this.limit &&
|
||||
this.results[0].rows.length < this.tableInfo.rows;
|
||||
this.results[0].rows.length < this.approximateCount;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
schema () {
|
||||
if (this.isSelected) {
|
||||
this.page = 1;
|
||||
this.approximateCount = 0;
|
||||
this.sortParams = {};
|
||||
this.getTableData();
|
||||
this.lastTable = this.table;
|
||||
@ -250,6 +251,7 @@ export default {
|
||||
table () {
|
||||
if (this.isSelected) {
|
||||
this.page = 1;
|
||||
this.approximateCount = 0;
|
||||
this.sortParams = {};
|
||||
this.getTableData();
|
||||
this.lastTable = this.table;
|
||||
@ -315,6 +317,20 @@ export default {
|
||||
this.addNotification({ status: 'error', message: err.stack });
|
||||
}
|
||||
|
||||
if (this.results.length && this.results[0].rows.length === this.limit) {
|
||||
try { // Table approximate count
|
||||
const { status, response } = await Tables.getTableApproximateCount(params);
|
||||
|
||||
if (status === 'success')
|
||||
this.approximateCount = response;
|
||||
else
|
||||
this.addNotification({ status: 'error', message: response });
|
||||
}
|
||||
catch (err) {
|
||||
this.addNotification({ status: 'error', message: err.stack });
|
||||
}
|
||||
}
|
||||
|
||||
this.isQuering = false;
|
||||
},
|
||||
getTable () {
|
||||
|
@ -10,6 +10,10 @@ export default class {
|
||||
return ipcRenderer.invoke('get-table-data', params);
|
||||
}
|
||||
|
||||
static getTableApproximateCount (params) {
|
||||
return ipcRenderer.invoke('get-table-count', params);
|
||||
}
|
||||
|
||||
static getTableIndexes (params) {
|
||||
return ipcRenderer.invoke('get-table-indexes', params);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user