connections pinger

This commit is contained in:
Jan Prochazka
2021-02-20 21:35:24 +01:00
parent 7a5bcc62c8
commit 28c1421294
7 changed files with 66 additions and 6 deletions

View File

@@ -0,0 +1,29 @@
import _ from 'lodash';
import { openedConnections, currentDatabase } from '../stores';
import axios from './axios';
const doServerPing = value => {
axios.post('server-connections/ping', { connections: value });
};
const doDatabasePing = value => {
const database = _.get(value, 'name');
const conid = _.get(value, 'connection._id');
if (conid && database) {
axios.post('database-connections/ping', { conid, database });
}
};
let openedConnectionsHandle = null;
openedConnections.subscribe(value => {
doServerPing(value);
if (openedConnectionsHandle) window.clearInterval(openedConnectionsHandle);
openedConnectionsHandle = window.setInterval(() => doServerPing(value), 30 * 1000);
});
let currentDatabaseHandle = null;
currentDatabase.subscribe(value => {
doDatabasePing(value);
if (currentDatabaseHandle) window.clearInterval(currentDatabaseHandle);
currentDatabaseHandle = window.setInterval(() => doDatabasePing(value), 30 * 1000);
});

View File

@@ -5,19 +5,20 @@ import stableStringify from 'json-stable-stringify';
import { cacheClean } from './cache';
import socket from './socket';
import getAsArray from './getAsArray';
import { DatabaseInfo } from 'dbgate-types';
const databaseInfoLoader = ({ conid, database }) => ({
url: 'database-connections/structure',
params: { conid, database },
reloadTrigger: `database-structure-changed-${conid}-${database}`,
transform: db => {
transform: (db: DatabaseInfo) => {
const allForeignKeys = _.flatten(db.tables.map(x => x.foreignKeys));
return {
...db,
tables: db.tables.map(table => ({
...table,
dependencies: allForeignKeys.filter(
(x: any) => x.refSchemaName == table.schemaName && x.refTableName == table.pureName
x => x.refSchemaName == table.schemaName && x.refTableName == table.pureName
),
})),
};