mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-22 00:36:01 +00:00
database connections
This commit is contained in:
22
packages/web/src/utility/ConnectionsPinger.js
Normal file
22
packages/web/src/utility/ConnectionsPinger.js
Normal file
@@ -0,0 +1,22 @@
|
||||
import React from 'react';
|
||||
import _ from 'lodash';
|
||||
import { useOpenedConnections, useCurrentDatabase } from './globalState';
|
||||
import axios from './axios';
|
||||
|
||||
export default function ConnectionsPinger({ children }) {
|
||||
const openedConnections = useOpenedConnections();
|
||||
const currentDatabase = useCurrentDatabase();
|
||||
React.useEffect(() => {
|
||||
const handle = window.setInterval(() => {
|
||||
axios.post('server-connections/ping', { connections: openedConnections });
|
||||
|
||||
const database = _.get(currentDatabase, 'name');
|
||||
const conid = _.get(currentDatabase, 'connection._id');
|
||||
if (conid && database) {
|
||||
axios.post('database-connections/ping', { conid });
|
||||
}
|
||||
}, 30 * 1000);
|
||||
return () => window.clearInterval(handle);
|
||||
}, [openedConnections, currentDatabase]);
|
||||
return children;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import React from 'react';
|
||||
import { useOpenedConnections } from './globalState';
|
||||
import axios from './axios';
|
||||
|
||||
export default function OpenedConnectionsPinger({ children }) {
|
||||
const openedConnections = useOpenedConnections();
|
||||
React.useEffect(() => {
|
||||
const handle = window.setInterval(() => {
|
||||
axios.post('server-connections/ping', { connections: openedConnections });
|
||||
}, 30 * 1000);
|
||||
return () => window.clearInterval(handle);
|
||||
}, [openedConnections]);
|
||||
return children;
|
||||
}
|
||||
Reference in New Issue
Block a user