mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-29 22:43:58 +00:00
optimalized connection ping
This commit is contained in:
@@ -8,6 +8,7 @@ const lock = new AsyncLock();
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
opened: [],
|
opened: [],
|
||||||
closed: {},
|
closed: {},
|
||||||
|
lastPinged: {},
|
||||||
|
|
||||||
handle_databases(conid, { databases }) {
|
handle_databases(conid, { databases }) {
|
||||||
const existing = this.opened.find(x => x.conid == conid);
|
const existing = this.opened.find(x => x.conid == conid);
|
||||||
@@ -88,7 +89,12 @@ module.exports = {
|
|||||||
ping_meta: 'post',
|
ping_meta: 'post',
|
||||||
async ping({ connections }) {
|
async ping({ connections }) {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
connections.map(async conid => {
|
_.uniq(connections).map(async conid => {
|
||||||
|
const last = this.lastPinged[conid];
|
||||||
|
if (last && new Date().getTime() - last < 30 * 1000) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
this.lastPinged[conid] = new Date().getTime();
|
||||||
const opened = await this.ensureOpened(conid);
|
const opened = await this.ensureOpened(conid);
|
||||||
opened.subprocess.send({ msgtype: 'ping' });
|
opened.subprocess.send({ msgtype: 'ping' });
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ function Menu({ data }) {
|
|||||||
setOpenedConnections(list => list.filter(x => x != data._id));
|
setOpenedConnections(list => list.filter(x => x != data._id));
|
||||||
};
|
};
|
||||||
const handleConnect = () => {
|
const handleConnect = () => {
|
||||||
setOpenedConnections(list => [...list, data._id]);
|
setOpenedConnections(list => _.uniq([...list, data._id]));
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -72,7 +72,7 @@ function ConnectionAppObject({ data, commonProps }) {
|
|||||||
const extensions = useExtensions();
|
const extensions = useExtensions();
|
||||||
|
|
||||||
const isBold = _.get(currentDatabase, 'connection._id') == _id;
|
const isBold = _.get(currentDatabase, 'connection._id') == _id;
|
||||||
const onClick = () => setOpenedConnections(c => [...c, _id]);
|
const onClick = () => setOpenedConnections(c => _.uniq([...c, _id]));
|
||||||
|
|
||||||
let statusIcon = null;
|
let statusIcon = null;
|
||||||
let statusTitle = null;
|
let statusTitle = null;
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ export default function ConnectionsPinger({ children }) {
|
|||||||
const openedConnections = useOpenedConnections();
|
const openedConnections = useOpenedConnections();
|
||||||
const currentDatabase = useCurrentDatabase();
|
const currentDatabase = useCurrentDatabase();
|
||||||
|
|
||||||
const doPing = () => {
|
const doServerPing = () => {
|
||||||
axios.post('server-connections/ping', { connections: openedConnections });
|
axios.post('server-connections/ping', { connections: openedConnections });
|
||||||
|
};
|
||||||
|
|
||||||
|
const doDatabasePing = () => {
|
||||||
const database = _.get(currentDatabase, 'name');
|
const database = _.get(currentDatabase, 'name');
|
||||||
const conid = _.get(currentDatabase, 'connection._id');
|
const conid = _.get(currentDatabase, 'connection._id');
|
||||||
if (conid && database) {
|
if (conid && database) {
|
||||||
@@ -18,9 +20,16 @@ export default function ConnectionsPinger({ children }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
doPing();
|
doServerPing();
|
||||||
const handle = window.setInterval(doPing, 30 * 1000);
|
const handle = window.setInterval(doServerPing, 30 * 1000);
|
||||||
return () => window.clearInterval(handle);
|
return () => window.clearInterval(handle);
|
||||||
}, [openedConnections, currentDatabase]);
|
}, [openedConnections]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
doDatabasePing();
|
||||||
|
const handle = window.setInterval(doDatabasePing, 30 * 1000);
|
||||||
|
return () => window.clearInterval(handle);
|
||||||
|
}, [currentDatabase]);
|
||||||
|
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user