mirror of
https://github.com/dbgate/dbgate
synced 2024-11-08 04:35:58 +00:00
fixed race conditions when starting app
This commit is contained in:
parent
e44a95d723
commit
9d933d669a
@ -43,7 +43,7 @@ async function handleFullRefresh() {
|
|||||||
loadingModel = false;
|
loadingModel = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleIncrementalRefresh() {
|
async function handleIncrementalRefresh(forceSend) {
|
||||||
loadingModel = true;
|
loadingModel = true;
|
||||||
const driver = requireEngineDriver(storedConnection);
|
const driver = requireEngineDriver(storedConnection);
|
||||||
setStatusName('checkStructure');
|
setStatusName('checkStructure');
|
||||||
@ -51,8 +51,12 @@ async function handleIncrementalRefresh() {
|
|||||||
analysedTime = new Date().getTime();
|
analysedTime = new Date().getTime();
|
||||||
if (newStructure != null) {
|
if (newStructure != null) {
|
||||||
analysedStructure = newStructure;
|
analysedStructure = newStructure;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (forceSend || newStructure != null) {
|
||||||
process.send({ msgtype: 'structure', structure: analysedStructure });
|
process.send({ msgtype: 'structure', structure: analysedStructure });
|
||||||
}
|
}
|
||||||
|
|
||||||
process.send({ msgtype: 'structureTime', analysedTime });
|
process.send({ msgtype: 'structureTime', analysedTime });
|
||||||
setStatusName('ok');
|
setStatusName('ok');
|
||||||
loadingModel = false;
|
loadingModel = false;
|
||||||
@ -91,7 +95,7 @@ async function handleConnect({ connection, structure, globalSettings }) {
|
|||||||
readVersion();
|
readVersion();
|
||||||
if (structure) {
|
if (structure) {
|
||||||
analysedStructure = structure;
|
analysedStructure = structure;
|
||||||
handleIncrementalRefresh();
|
handleIncrementalRefresh(true);
|
||||||
} else {
|
} else {
|
||||||
handleFullRefresh();
|
handleFullRefresh();
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,47 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
|
||||||
import CommandListener from './commands/CommandListener.svelte';
|
import CommandListener from './commands/CommandListener.svelte';
|
||||||
import DataGridRowHeightMeter from './datagrid/DataGridRowHeightMeter.svelte';
|
import DataGridRowHeightMeter from './datagrid/DataGridRowHeightMeter.svelte';
|
||||||
import LoadingInfo from './elements/LoadingInfo.svelte';
|
import LoadingInfo from './elements/LoadingInfo.svelte';
|
||||||
|
|
||||||
import PluginsProvider from './plugins/PluginsProvider.svelte';
|
import PluginsProvider from './plugins/PluginsProvider.svelte';
|
||||||
import Screen from './Screen.svelte';
|
import Screen from './Screen.svelte';
|
||||||
|
import { setAppLoaded } from './utility/appLoadManager';
|
||||||
|
import axiosInstance from './utility/axiosInstance';
|
||||||
import ErrorHandler from './utility/ErrorHandler.svelte';
|
import ErrorHandler from './utility/ErrorHandler.svelte';
|
||||||
import { useSettings } from './utility/metadataLoaders';
|
|
||||||
import OpenTabsOnStartup from './utility/OpenTabsOnStartup.svelte';
|
import OpenTabsOnStartup from './utility/OpenTabsOnStartup.svelte';
|
||||||
|
|
||||||
const settings = useSettings();
|
let loaded = false;
|
||||||
|
|
||||||
|
async function loadSettings() {
|
||||||
|
try {
|
||||||
|
const settings = await axiosInstance.get('config/get-settings');
|
||||||
|
const connections = await axiosInstance.get('connections/list');
|
||||||
|
const config = await axiosInstance.get('config/get');
|
||||||
|
loaded = settings?.data && connections?.data && config?.data;
|
||||||
|
if (loaded) {
|
||||||
|
setAppLoaded();
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.log('Error loading settings, trying again in 1s');
|
||||||
|
setTimeout(loadSettings, 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(loadSettings);
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<DataGridRowHeightMeter />
|
<DataGridRowHeightMeter />
|
||||||
<ErrorHandler />
|
<ErrorHandler />
|
||||||
<PluginsProvider />
|
|
||||||
<CommandListener />
|
<CommandListener />
|
||||||
|
|
||||||
|
{#if loaded}
|
||||||
|
<PluginsProvider />
|
||||||
<OpenTabsOnStartup />
|
<OpenTabsOnStartup />
|
||||||
|
|
||||||
{#if $settings}
|
|
||||||
<Screen />
|
<Screen />
|
||||||
{:else}
|
{:else}
|
||||||
<LoadingInfo message="Loading settings..." wrapper />
|
<LoadingInfo message="Starting DbGate API..." wrapper />
|
||||||
{/if}
|
{/if}
|
||||||
|
22
packages/web/src/utility/appLoadManager.ts
Normal file
22
packages/web/src/utility/appLoadManager.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
let appIsLoaded = false;
|
||||||
|
let onLoad = [];
|
||||||
|
|
||||||
|
export function setAppLoaded() {
|
||||||
|
appIsLoaded = true;
|
||||||
|
for (const func of onLoad) {
|
||||||
|
func();
|
||||||
|
}
|
||||||
|
onLoad = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAppLoaded() {
|
||||||
|
return appIsLoaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function callWhenAppLoaded(callback) {
|
||||||
|
if (appIsLoaded) {
|
||||||
|
callback();
|
||||||
|
} else {
|
||||||
|
onLoad.push(callback);
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,11 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { currentDatabase, openedTabs } from '../stores';
|
import { currentDatabase, openedTabs } from '../stores';
|
||||||
|
import { callWhenAppLoaded } from './appLoadManager';
|
||||||
import { getConnectionInfo } from './metadataLoaders';
|
import { getConnectionInfo } from './metadataLoaders';
|
||||||
|
|
||||||
let lastCurrentTab = null;
|
let lastCurrentTab = null;
|
||||||
|
|
||||||
openedTabs.subscribe(async value => {
|
openedTabs.subscribe(value => {
|
||||||
const newCurrentTab = (value || []).find(x => x.selected);
|
const newCurrentTab = (value || []).find(x => x.selected);
|
||||||
if (newCurrentTab == lastCurrentTab) return;
|
if (newCurrentTab == lastCurrentTab) return;
|
||||||
|
|
||||||
@ -15,11 +16,14 @@ openedTabs.subscribe(async value => {
|
|||||||
database &&
|
database &&
|
||||||
(conid != _.get(lastCurrentTab, 'props.conid') || database != _.get(lastCurrentTab, 'props.database'))
|
(conid != _.get(lastCurrentTab, 'props.conid') || database != _.get(lastCurrentTab, 'props.database'))
|
||||||
) {
|
) {
|
||||||
|
const doWork = async () => {
|
||||||
const connection = await getConnectionInfo({ conid });
|
const connection = await getConnectionInfo({ conid });
|
||||||
currentDatabase.set({
|
currentDatabase.set({
|
||||||
connection,
|
connection,
|
||||||
name: database,
|
name: database,
|
||||||
});
|
});
|
||||||
|
};
|
||||||
|
callWhenAppLoaded(doWork);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user