Skip to content

Commit

Permalink
Connectors: query invalidations (#5014)
Browse files Browse the repository at this point in the history
* Correctly invalidate the Tables list when a Connector changes

* Fix accidental query cancellation

* Invalidate `AnalyzeConnectors` when a Connector changes
  • Loading branch information
ericpgreen2 committed Jun 4, 2024
1 parent e81a68d commit 1802181
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 26 deletions.
41 changes: 19 additions & 22 deletions web-common/src/features/connectors/olap/DatabaseExplorer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,30 @@
export let instanceId: string;
export let connector: V1AnalyzedConnector;
let dataBasesQuery: ReturnType<typeof useDatabases>;
$: if (connector.name) {
dataBasesQuery = useDatabases(instanceId, connector?.name);
}
$: connectorName = connector?.name as string;
$: dataBasesQuery = useDatabases(instanceId, connectorName);
$: ({ data, error, isLoading } = $dataBasesQuery);
</script>

{#if connector && connector.name}
<div class="wrapper">
{#if error}
<span class="message">Error: {error.response.data.message}</span>
{:else if isLoading}
<span class="message">Loading databases...</span>
{:else if data}
{#if data.length === 0}
<span class="message">No databases found</span>
{:else}
<ol transition:slide={{ duration }}>
{#each data as database (database)}
<DatabaseEntry {instanceId} {connector} {database} />
{/each}
</ol>
{/if}
<div class="wrapper">
{#if error}
<span class="message">Error: {error.response.data.message}</span>
{:else if isLoading}
<span class="message">Loading databases...</span>
{:else if data}
{#if data.length === 0}
<span class="message">No databases found</span>
{:else}
<ol transition:slide={{ duration }}>
{#each data as database (database)}
<DatabaseEntry {instanceId} {connector} {database} />
{/each}
</ol>
{/if}
</div>
{/if}
{/if}
</div>

<style lang="postcss">
.wrapper {
Expand Down
16 changes: 16 additions & 0 deletions web-common/src/features/connectors/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { V1Resource } from "../../runtime-client";
import { ResourceKind } from "../entity-management/resource-selectors";

export function getConnectorNameForResource(resource: V1Resource): string {
if (!resource.meta?.name?.kind || !resource.meta?.name?.name) return "";

if (resource.meta.name.kind === ResourceKind.Connector.toString()) {
return resource.meta.name.name;
} else if (resource.meta.name.kind === ResourceKind.Source.toString()) {
return resource?.source?.spec?.sinkConnector ?? "";
} else if (resource.meta.name.kind === ResourceKind.Model.toString()) {
return resource?.model?.spec?.outputConnector ?? "";
}

return "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ResourceKind } from "@rilldata/web-common/features/entity-management/re
import { queryClient } from "@rilldata/web-common/lib/svelte-query/globalQueryClient";
import {
getConnectorServiceOLAPListTablesQueryKey,
getRuntimeServiceAnalyzeConnectorsQueryKey,
getRuntimeServiceGetResourceQueryKey,
getRuntimeServiceListResourcesQueryKey,
V1ReconcileStatus,
Expand All @@ -21,6 +22,7 @@ import { isProfilingQuery } from "@rilldata/web-common/runtime-client/query-matc
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
import { WatchRequestClient } from "@rilldata/web-common/runtime-client/watch-request-client";
import { get } from "svelte/store";
import { getConnectorNameForResource } from "../connectors/utils";

const MainResourceKinds: {
[kind in ResourceKind]?: true;
Expand Down Expand Up @@ -144,10 +146,7 @@ export class WatchResourcesClient {
void queryClient.invalidateQueries(
getConnectorServiceOLAPListTablesQueryKey({
instanceId: get(runtime).instanceId,
connector:
resource.source?.spec?.sinkConnector ??
resource.model?.spec?.outputConnector ??
"",
connector: getConnectorNameForResource(resource),
}),
);
}
Expand All @@ -158,6 +157,11 @@ export class WatchResourcesClient {
const name = resource.meta?.name?.name ?? "";
let table: string | undefined;
switch (resource.meta.name?.kind) {
case ResourceKind.Connector:
void queryClient.invalidateQueries(
getRuntimeServiceAnalyzeConnectorsQueryKey(instanceId),
);
return;
case ResourceKind.Source:
case ResourceKind.Model:
table =
Expand Down

2 comments on commit 1802181

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://ui.rilldata.com as production
🚀 Deployed on https://665f9f1c86974f6d508295ad--rill-ui.netlify.app

Please sign in to comment.