optimalized connection ping

This commit is contained in:
Jan Prochazka
2021-01-28 08:16:31 +01:00
parent a3294950a4
commit ca4ff95316
3 changed files with 22 additions and 7 deletions

View File

@@ -7,9 +7,11 @@ export default function ConnectionsPinger({ children }) {
const openedConnections = useOpenedConnections();
const currentDatabase = useCurrentDatabase();
const doPing = () => {
const doServerPing = () => {
axios.post('server-connections/ping', { connections: openedConnections });
};
const doDatabasePing = () => {
const database = _.get(currentDatabase, 'name');
const conid = _.get(currentDatabase, 'connection._id');
if (conid && database) {
@@ -18,9 +20,16 @@ export default function ConnectionsPinger({ children }) {
};
React.useEffect(() => {
doPing();
const handle = window.setInterval(doPing, 30 * 1000);
doServerPing();
const handle = window.setInterval(doServerPing, 30 * 1000);
return () => window.clearInterval(handle);
}, [openedConnections, currentDatabase]);
}, [openedConnections]);
React.useEffect(() => {
doDatabasePing();
const handle = window.setInterval(doDatabasePing, 30 * 1000);
return () => window.clearInterval(handle);
}, [currentDatabase]);
return children;
}