load db structure progress (postgresql) #273

This commit is contained in:
Jan Prochazka
2022-05-26 16:32:05 +02:00
parent affb935f63
commit 3f22960849
4 changed files with 29 additions and 7 deletions

View File

@@ -15,6 +15,7 @@ let afterConnectCallbacks = [];
let afterAnalyseCallbacks = [];
let analysedStructure = null;
let lastPing = null;
let lastStatusString = null;
let lastStatus = null;
let analysedTime = 0;
let serverVersion;
@@ -84,15 +85,17 @@ function handleSyncModel() {
}
function setStatus(status) {
const statusString = stableStringify(status);
if (lastStatus != statusString) {
process.send({ msgtype: 'status', status: { ...status, counter: getStatusCounter() } });
lastStatus = statusString;
const newStatus = { ...lastStatus, ...status };
const statusString = stableStringify(newStatus);
if (lastStatusString != statusString) {
process.send({ msgtype: 'status', status: { ...newStatus, counter: getStatusCounter() } });
lastStatusString = statusString;
lastStatus = newStatus;
}
}
function setStatusName(name) {
setStatus({ name });
setStatus({ name, message: null });
}
async function readVersion() {
@@ -109,6 +112,7 @@ async function handleConnect({ connection, structure, globalSettings }) {
if (!structure) setStatusName('pending');
const driver = requireEngineDriver(storedConnection);
systemConnection = await checkedAsyncCall(connectUtility(driver, storedConnection, 'app'));
systemConnection.feedback = feedback => setStatus({ feedback });
await checkedAsyncCall(readVersion());
if (structure) {
analysedStructure = structure;

View File

@@ -220,6 +220,12 @@ export class DatabaseAnalyser {
];
}
feedback(obj) {
if (this.pool.feedback) {
this.pool.feedback(obj);
}
}
async getModifications() {
const snapshot = await this._getFastSnapshot();
if (!snapshot) return null;

View File

@@ -65,7 +65,7 @@
objectTypeField: 'queries',
pureName: query.name,
schemaName: app.name,
sql: query.sql
sql: query.sql,
}))
),
]);
@@ -134,7 +134,7 @@
</SearchBoxWrapper>
<WidgetsInnerContainer>
{#if ($status && ($status.name == 'pending' || $status.name == 'checkStructure' || $status.name == 'loadStructure') && $objects) || !$objects}
<LoadingInfo message="Loading database structure" />
<LoadingInfo message={$status?.feedback?.analysingMessage || 'Loading database structure'} />
{:else}
<AppObjectList
list={objectList.map(x => ({ ...x, conid, database }))}

View File

@@ -52,28 +52,40 @@ class Analyser extends DatabaseAnalyser {
}
async _runAnalysis() {
this.feedback({ analysingMessage: 'Loading tables' });
const tables = await this.driver.query(
this.pool,
this.createQuery(this.driver.dialect.stringAgg ? 'tableModifications' : 'tableList', ['tables'])
);
this.feedback({ analysingMessage: 'Loading columns' });
const columns = await this.driver.query(this.pool, this.createQuery('columns', ['tables', 'views']));
this.feedback({ analysingMessage: 'Loading primary keys' });
const pkColumns = await this.driver.query(this.pool, this.createQuery('primaryKeys', ['tables']));
this.feedback({ analysingMessage: 'Loading foreign keys' });
const fkColumns = await this.driver.query(this.pool, this.createQuery('foreignKeys', ['tables']));
this.feedback({ analysingMessage: 'Loading views' });
const views = await this.driver.query(this.pool, this.createQuery('views', ['views']));
this.feedback({ analysingMessage: 'Loading materialized views' });
const matviews = this.driver.dialect.materializedViews
? await this.driver.query(this.pool, this.createQuery('matviews', ['matviews']))
: null;
this.feedback({ analysingMessage: 'Loading materialized view columns' });
const matviewColumns = this.driver.dialect.materializedViews
? await this.driver.query(this.pool, this.createQuery('matviewColumns', ['matviews']))
: null;
this.feedback({ analysingMessage: 'Loading routines' });
const routines = await this.driver.query(this.pool, this.createQuery('routines', ['procedures', 'functions']));
this.feedback({ analysingMessage: 'Loading indexes' });
const indexes = this.driver.__analyserInternals.skipIndexes
? { rows: [] }
: await this.driver.query(this.pool, this.createQuery('indexes', ['tables']));
this.feedback({ analysingMessage: 'Loading index columns' });
const indexcols = this.driver.__analyserInternals.skipIndexes
? { rows: [] }
: await this.driver.query(this.pool, this.createQuery('indexcols', ['tables']));
this.feedback({ analysingMessage: 'Loading unique names' });
const uniqueNames = await this.driver.query(this.pool, this.createQuery('uniqueNames', ['tables']));
this.feedback({ analysingMessage: null });
return {
tables: tables.rows.map(table => {