mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-28 15:16:00 +00:00
ability to disable background model updates
This commit is contained in:
@@ -4,6 +4,7 @@ const socket = require('../utility/socket');
|
|||||||
const { fork } = require('child_process');
|
const { fork } = require('child_process');
|
||||||
const { DatabaseAnalyser } = require('dbgate-tools');
|
const { DatabaseAnalyser } = require('dbgate-tools');
|
||||||
const { handleProcessCommunication } = require('../utility/processComm');
|
const { handleProcessCommunication } = require('../utility/processComm');
|
||||||
|
const config = require('./config');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
/** @type {import('dbgate-types').OpenedDatabaseConnection[]} */
|
/** @type {import('dbgate-types').OpenedDatabaseConnection[]} */
|
||||||
@@ -79,6 +80,7 @@ module.exports = {
|
|||||||
msgtype: 'connect',
|
msgtype: 'connect',
|
||||||
connection: { ...connection, database },
|
connection: { ...connection, database },
|
||||||
structure: lastClosed ? lastClosed.structure : null,
|
structure: lastClosed ? lastClosed.structure : null,
|
||||||
|
globalSettings: await config.getSettings()
|
||||||
});
|
});
|
||||||
return newOpened;
|
return newOpened;
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const _ = require('lodash');
|
|||||||
const AsyncLock = require('async-lock');
|
const AsyncLock = require('async-lock');
|
||||||
const { handleProcessCommunication } = require('../utility/processComm');
|
const { handleProcessCommunication } = require('../utility/processComm');
|
||||||
const lock = new AsyncLock();
|
const lock = new AsyncLock();
|
||||||
|
const config = require('./config');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
opened: [],
|
opened: [],
|
||||||
@@ -65,7 +66,7 @@ module.exports = {
|
|||||||
if (newOpened.disconnected) return;
|
if (newOpened.disconnected) return;
|
||||||
this.close(conid, false);
|
this.close(conid, false);
|
||||||
});
|
});
|
||||||
subprocess.send({ msgtype: 'connect', ...connection });
|
subprocess.send({ msgtype: 'connect', ...connection, globalSettings: await config.getSettings() });
|
||||||
return newOpened;
|
return newOpened;
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
const stableStringify = require('json-stable-stringify');
|
const stableStringify = require('json-stable-stringify');
|
||||||
const childProcessChecker = require('../utility/childProcessChecker');
|
const childProcessChecker = require('../utility/childProcessChecker');
|
||||||
|
const { extractBoolSettingsValue, extractIntSettingsValue } = require('dbgate-tools');
|
||||||
const requireEngineDriver = require('../utility/requireEngineDriver');
|
const requireEngineDriver = require('../utility/requireEngineDriver');
|
||||||
const connectUtility = require('../utility/connectUtility');
|
const connectUtility = require('../utility/connectUtility');
|
||||||
const { handleProcessCommunication } = require('../utility/processComm');
|
const { handleProcessCommunication } = require('../utility/processComm');
|
||||||
@@ -64,7 +65,7 @@ async function readVersion() {
|
|||||||
process.send({ msgtype: 'version', version });
|
process.send({ msgtype: 'version', version });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleConnect({ connection, structure }) {
|
async function handleConnect({ connection, structure, globalSettings }) {
|
||||||
storedConnection = connection;
|
storedConnection = connection;
|
||||||
lastPing = new Date().getTime();
|
lastPing = new Date().getTime();
|
||||||
|
|
||||||
@@ -78,7 +79,14 @@ async function handleConnect({ connection, structure }) {
|
|||||||
} else {
|
} else {
|
||||||
handleFullRefresh();
|
handleFullRefresh();
|
||||||
}
|
}
|
||||||
setInterval(handleIncrementalRefresh, 30 * 1000);
|
|
||||||
|
if (extractBoolSettingsValue(globalSettings, 'connection.autoRefresh', true)) {
|
||||||
|
setInterval(
|
||||||
|
handleIncrementalRefresh,
|
||||||
|
extractIntSettingsValue(globalSettings, 'connection.autoRefreshInterval', 30, 3, 3600) * 1000
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
for (const [resolve] of afterConnectCallbacks) {
|
for (const [resolve] of afterConnectCallbacks) {
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
const stableStringify = require('json-stable-stringify');
|
const stableStringify = require('json-stable-stringify');
|
||||||
|
const { extractBoolSettingsValue, extractIntSettingsValue } = require('dbgate-tools');
|
||||||
const childProcessChecker = require('../utility/childProcessChecker');
|
const childProcessChecker = require('../utility/childProcessChecker');
|
||||||
const requireEngineDriver = require('../utility/requireEngineDriver');
|
const requireEngineDriver = require('../utility/requireEngineDriver');
|
||||||
const { decryptConnection } = require('../utility/crypting');
|
const { decryptConnection } = require('../utility/crypting');
|
||||||
@@ -51,6 +52,7 @@ function setStatusName(name) {
|
|||||||
|
|
||||||
async function handleConnect(connection) {
|
async function handleConnect(connection) {
|
||||||
storedConnection = connection;
|
storedConnection = connection;
|
||||||
|
const { globalSettings } = storedConnection;
|
||||||
setStatusName('pending');
|
setStatusName('pending');
|
||||||
lastPing = new Date().getTime();
|
lastPing = new Date().getTime();
|
||||||
|
|
||||||
@@ -59,7 +61,9 @@ async function handleConnect(connection) {
|
|||||||
systemConnection = await connectUtility(driver, storedConnection);
|
systemConnection = await connectUtility(driver, storedConnection);
|
||||||
readVersion();
|
readVersion();
|
||||||
handleRefresh();
|
handleRefresh();
|
||||||
setInterval(handleRefresh, 30 * 1000);
|
if (extractBoolSettingsValue(globalSettings, 'connection.autoRefresh', true)) {
|
||||||
|
setInterval(handleRefresh, extractIntSettingsValue(globalSettings, 'connection.autoRefreshInterval', 30, 5, 3600) * 1000);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setStatus({
|
setStatus({
|
||||||
name: 'error',
|
name: 'error',
|
||||||
|
|||||||
@@ -9,3 +9,4 @@ export * from './SqlDumper';
|
|||||||
export * from './testPermission';
|
export * from './testPermission';
|
||||||
export * from './SqlGenerator';
|
export * from './SqlGenerator';
|
||||||
export * from './structureTools';
|
export * from './structureTools';
|
||||||
|
export * from './settingsExtractors';
|
||||||
|
|||||||
20
packages/tools/src/settingsExtractors.ts
Normal file
20
packages/tools/src/settingsExtractors.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
export function extractIntSettingsValue(settings, name, defaultValue, min = null, max = null) {
|
||||||
|
const parsed = parseInt(settings[name]);
|
||||||
|
if (_.isNaN(parsed)) {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
if (_.isNumber(parsed)) {
|
||||||
|
if (min != null && parsed < min) return min;
|
||||||
|
if (max != null && parsed > max) return max;
|
||||||
|
return parsed;
|
||||||
|
}
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function extractBoolSettingsValue(settings, name, defaultValue) {
|
||||||
|
const res = settings[name];
|
||||||
|
if (res == null) return defaultValue;
|
||||||
|
return !!res;
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
import FormProvider from '../forms/FormProvider.svelte';
|
import FormProvider from '../forms/FormProvider.svelte';
|
||||||
import FormSubmit from '../forms/FormSubmit.svelte';
|
import FormSubmit from '../forms/FormSubmit.svelte';
|
||||||
import FormTextField from '../forms/FormTextField.svelte';
|
import FormTextField from '../forms/FormTextField.svelte';
|
||||||
|
import FormValues from '../forms/FormValues.svelte';
|
||||||
|
|
||||||
import ModalBase from '../modals/ModalBase.svelte';
|
import ModalBase from '../modals/ModalBase.svelte';
|
||||||
import { closeCurrentModal } from '../modals/modalTools';
|
import { closeCurrentModal } from '../modals/modalTools';
|
||||||
@@ -32,6 +33,7 @@
|
|||||||
<ModalBase {...$$restProps}>
|
<ModalBase {...$$restProps}>
|
||||||
<div slot="header">Settings</div>
|
<div slot="header">Settings</div>
|
||||||
|
|
||||||
|
<FormValues let:values>
|
||||||
<div class="heading">Appearance</div>
|
<div class="heading">Appearance</div>
|
||||||
<FormCheckboxField name=":visibleToolbar" label="Show toolbar" defaultValue={true} />
|
<FormCheckboxField name=":visibleToolbar" label="Show toolbar" defaultValue={true} />
|
||||||
|
|
||||||
@@ -44,6 +46,20 @@
|
|||||||
/>
|
/>
|
||||||
<FormCheckboxField name="dataGrid.showHintColumns" label="Show foreign key hints" defaultValue={true} />
|
<FormCheckboxField name="dataGrid.showHintColumns" label="Show foreign key hints" defaultValue={true} />
|
||||||
|
|
||||||
|
<div class="heading">Connection</div>
|
||||||
|
<FormCheckboxField
|
||||||
|
name="connection.autoRefresh"
|
||||||
|
label="Automatic refresh of database model on background"
|
||||||
|
defaultValue={true}
|
||||||
|
/>
|
||||||
|
<FormTextField
|
||||||
|
name="connection.autoRefreshInterval"
|
||||||
|
label="Interval between automatic refreshes in seconds"
|
||||||
|
defaultValue="30"
|
||||||
|
disabled={values['connection.autoRefresh'] === false}
|
||||||
|
/>
|
||||||
|
</FormValues>
|
||||||
|
|
||||||
<div slot="footer">
|
<div slot="footer">
|
||||||
<FormSubmit value="OK" on:click={handleOk} />
|
<FormSubmit value="OK" on:click={handleOk} />
|
||||||
<FormButton value="Cancel" on:click={closeCurrentModal} />
|
<FormButton value="Cancel" on:click={closeCurrentModal} />
|
||||||
|
|||||||
Reference in New Issue
Block a user