mirror of
https://github.com/Fabio286/antares.git
synced 2025-04-25 07:18:46 +02: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) => {
|
ipcMain.handle('get-table-indexes', async (event, params) => {
|
||||||
try {
|
try {
|
||||||
const result = await connections[params.uid].getTableIndexes(params);
|
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 {Object} params
|
||||||
* @param {String} params.schema
|
* @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 {Object} params
|
||||||
* @param {String} params.schema
|
* @param {String} params.schema
|
||||||
|
@ -104,7 +104,7 @@ export default {
|
|||||||
return this.getWorkspace(this.selectedWorkspace);
|
return this.getWorkspace(this.selectedWorkspace);
|
||||||
},
|
},
|
||||||
customizations () {
|
customizations () {
|
||||||
return this.workspace ? this.workspace.customizations : {};
|
return this.workspace && this.workspace.customizations ? this.workspace.customizations : {};
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -112,8 +112,8 @@
|
|||||||
<div v-if="results.length && results[0].rows">
|
<div v-if="results.length && results[0].rows">
|
||||||
{{ $t('word.results') }}: <b>{{ results[0].rows.length | localeString }}</b>
|
{{ $t('word.results') }}: <b>{{ results[0].rows.length | localeString }}</b>
|
||||||
</div>
|
</div>
|
||||||
<div v-if="hasApproximately || (page > 1 && tableInfo.rows)">
|
<div v-if="hasApproximately || (page > 1 && approximateCount)">
|
||||||
{{ $t('word.total') }}: <b>{{ tableInfo.rows | localeString }}</b> <small>({{ $t('word.approximately') }})</small>
|
{{ $t('word.total') }}: <b :title="$t('word.approximately')">≈ {{ approximateCount | localeString }}</b>
|
||||||
</div>
|
</div>
|
||||||
<div class="d-flex" :title="$t('word.schema')">
|
<div class="d-flex" :title="$t('word.schema')">
|
||||||
<i class="mdi mdi-18px mdi-database mr-1" /><b>{{ schema }}</b>
|
<i class="mdi mdi-18px mdi-database mr-1" /><b>{{ schema }}</b>
|
||||||
@ -175,7 +175,7 @@ export default {
|
|||||||
},
|
},
|
||||||
filters: {
|
filters: {
|
||||||
localeString (val) {
|
localeString (val) {
|
||||||
if (val)
|
if (val !== null)
|
||||||
return val.toLocaleString();
|
return val.toLocaleString();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -200,7 +200,8 @@ export default {
|
|||||||
refreshInterval: null,
|
refreshInterval: null,
|
||||||
sortParams: {},
|
sortParams: {},
|
||||||
page: 1,
|
page: 1,
|
||||||
pageProxy: 1
|
pageProxy: 1,
|
||||||
|
approximateCount: 0
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -232,15 +233,15 @@ export default {
|
|||||||
hasApproximately () {
|
hasApproximately () {
|
||||||
return this.results.length &&
|
return this.results.length &&
|
||||||
this.results[0].rows &&
|
this.results[0].rows &&
|
||||||
this.tableInfo &&
|
|
||||||
this.results[0].rows.length === this.limit &&
|
this.results[0].rows.length === this.limit &&
|
||||||
this.results[0].rows.length < this.tableInfo.rows;
|
this.results[0].rows.length < this.approximateCount;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
schema () {
|
schema () {
|
||||||
if (this.isSelected) {
|
if (this.isSelected) {
|
||||||
this.page = 1;
|
this.page = 1;
|
||||||
|
this.approximateCount = 0;
|
||||||
this.sortParams = {};
|
this.sortParams = {};
|
||||||
this.getTableData();
|
this.getTableData();
|
||||||
this.lastTable = this.table;
|
this.lastTable = this.table;
|
||||||
@ -250,6 +251,7 @@ export default {
|
|||||||
table () {
|
table () {
|
||||||
if (this.isSelected) {
|
if (this.isSelected) {
|
||||||
this.page = 1;
|
this.page = 1;
|
||||||
|
this.approximateCount = 0;
|
||||||
this.sortParams = {};
|
this.sortParams = {};
|
||||||
this.getTableData();
|
this.getTableData();
|
||||||
this.lastTable = this.table;
|
this.lastTable = this.table;
|
||||||
@ -315,6 +317,20 @@ export default {
|
|||||||
this.addNotification({ status: 'error', message: err.stack });
|
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;
|
this.isQuering = false;
|
||||||
},
|
},
|
||||||
getTable () {
|
getTable () {
|
||||||
|
@ -10,6 +10,10 @@ export default class {
|
|||||||
return ipcRenderer.invoke('get-table-data', params);
|
return ipcRenderer.invoke('get-table-data', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getTableApproximateCount (params) {
|
||||||
|
return ipcRenderer.invoke('get-table-count', params);
|
||||||
|
}
|
||||||
|
|
||||||
static getTableIndexes (params) {
|
static getTableIndexes (params) {
|
||||||
return ipcRenderer.invoke('get-table-indexes', params);
|
return ipcRenderer.invoke('get-table-indexes', params);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user