redis key loading refactor

This commit is contained in:
SPRINX0\prochazka
2025-01-22 16:35:54 +01:00
parent db86ae627f
commit 41e5089ab3
5 changed files with 249 additions and 96 deletions

View File

@@ -1,9 +1,8 @@
<script lang="ts">
import { findEngineDriver } from 'dbgate-tools';
import { dbKeys_loadMissing, dbKeys_refreshAll, findEngineDriver } from 'dbgate-tools';
import CloseSearchButton from '../buttons/CloseSearchButton.svelte';
import InlineButton from '../buttons/InlineButton.svelte';
import runCommand from '../commands/runCommand';
import SearchBoxWrapper from '../elements/SearchBoxWrapper.svelte';
import SearchInput from '../elements/SearchInput.svelte';
@@ -17,15 +16,16 @@
import DbKeysSubTree from './DbKeysSubTree.svelte';
import WidgetsInnerContainer from './WidgetsInnerContainer.svelte';
import FocusedConnectionInfoWidget from './FocusedConnectionInfoWidget.svelte';
export let conid;
export let database;
let filter;
let reloadToken = 0;
let model = dbKeys_refreshAll();
function handleRefreshDatabase() {
reloadToken += 1;
changeModel(model => dbKeys_refreshAll(model));
}
function handleAddKey() {
@@ -58,6 +58,31 @@
($focusedConnectionOrDatabase?.database && $focusedConnectionOrDatabase?.database != database));
$: connection = useConnectionInfo({ conid });
async function changeModel(modelUpdate) {
model = modelUpdate(model);
model = await dbKeys_loadMissing(model, async (root, limit) => {
const result = await apiCall('database-connections/load-keys', {
conid,
database,
root,
filter,
limit,
});
return result;
});
}
function reloadModel() {
changeModel(model => dbKeys_refreshAll(model));
}
$: {
conid;
database;
filter;
reloadModel();
}
</script>
<SearchBoxWrapper>
@@ -74,5 +99,5 @@
<FocusedConnectionInfoWidget {conid} {database} connection={$connection} />
{/if}
<WidgetsInnerContainer hideContent={differentFocusedDb}>
<DbKeysSubTree {conid} {database} root="" {reloadToken} connection={$currentDatabase?.connection} {filter} />
<DbKeysSubTree root="" {filter} {model} {changeModel} {conid} {database} {connection} />
</WidgetsInnerContainer>