fixed race conditions when starting app

This commit is contained in:
Jan Prochazka 2021-05-17 17:42:53 +02:00
parent e44a95d723
commit 9d933d669a
4 changed files with 66 additions and 14 deletions

View File

@ -43,7 +43,7 @@ async function handleFullRefresh() {
loadingModel = false;
}
async function handleIncrementalRefresh() {
async function handleIncrementalRefresh(forceSend) {
loadingModel = true;
const driver = requireEngineDriver(storedConnection);
setStatusName('checkStructure');
@ -51,8 +51,12 @@ async function handleIncrementalRefresh() {
analysedTime = new Date().getTime();
if (newStructure != null) {
analysedStructure = newStructure;
}
if (forceSend || newStructure != null) {
process.send({ msgtype: 'structure', structure: analysedStructure });
}
process.send({ msgtype: 'structureTime', analysedTime });
setStatusName('ok');
loadingModel = false;
@ -91,7 +95,7 @@ async function handleConnect({ connection, structure, globalSettings }) {
readVersion();
if (structure) {
analysedStructure = structure;
handleIncrementalRefresh();
handleIncrementalRefresh(true);
} else {
handleFullRefresh();
}

View File

@ -1,25 +1,47 @@
<script lang="ts">
import { onMount } from 'svelte';
import CommandListener from './commands/CommandListener.svelte';
import DataGridRowHeightMeter from './datagrid/DataGridRowHeightMeter.svelte';
import LoadingInfo from './elements/LoadingInfo.svelte';
import PluginsProvider from './plugins/PluginsProvider.svelte';
import Screen from './Screen.svelte';
import { setAppLoaded } from './utility/appLoadManager';
import axiosInstance from './utility/axiosInstance';
import ErrorHandler from './utility/ErrorHandler.svelte';
import { useSettings } from './utility/metadataLoaders';
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>
<DataGridRowHeightMeter />
<ErrorHandler />
<PluginsProvider />
<CommandListener />
{#if loaded}
<PluginsProvider />
<OpenTabsOnStartup />
{#if $settings}
<Screen />
{:else}
<LoadingInfo message="Loading settings..." wrapper />
<LoadingInfo message="Starting DbGate API..." wrapper />
{/if}

View 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);
}
}

View File

@ -1,10 +1,11 @@
import _ from 'lodash';
import { currentDatabase, openedTabs } from '../stores';
import { callWhenAppLoaded } from './appLoadManager';
import { getConnectionInfo } from './metadataLoaders';
let lastCurrentTab = null;
openedTabs.subscribe(async value => {
openedTabs.subscribe(value => {
const newCurrentTab = (value || []).find(x => x.selected);
if (newCurrentTab == lastCurrentTab) return;
@ -15,11 +16,14 @@ openedTabs.subscribe(async value => {
database &&
(conid != _.get(lastCurrentTab, 'props.conid') || database != _.get(lastCurrentTab, 'props.database'))
) {
const doWork = async () => {
const connection = await getConnectionInfo({ conid });
currentDatabase.set({
connection,
name: database,
});
};
callWhenAppLoaded(doWork);
}
}