Skip to content

Commit

Permalink
perf(ui-ingestion): cache on creation or deletion of ingestion source…
Browse files Browse the repository at this point in the history
…s to reduce latency
  • Loading branch information
aditya-radhakrishnan committed Dec 6, 2022
1 parent 88d2d9b commit 18a6c7f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 3 deletions.
16 changes: 14 additions & 2 deletions datahub-web-react/src/app/ingest/source/IngestionSourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { Message } from '../../shared/Message';
import TabToolbar from '../../entity/shared/components/styled/TabToolbar';
import { IngestionSourceBuilderModal } from './builder/IngestionSourceBuilderModal';
import { CLI_EXECUTOR_ID } from './utils';
import { addToListIngestionSourcesCache, CLI_EXECUTOR_ID, removeFromListIngestionSourcesCache } from './utils';
import { DEFAULT_EXECUTOR_ID, SourceBuilderState } from './builder/types';
import { IngestionSource, UpdateIngestionSourceInput } from '../../../types.generated';
import { SearchBar } from '../../search/SearchBar';
Expand Down Expand Up @@ -96,14 +96,15 @@ export const IngestionSourceList = () => {
const [sourceFilter, setSourceFilter] = useState(IngestionSourceType.ALL);

// Ingestion Source Queries
const { loading, error, data, refetch } = useListIngestionSourcesQuery({
const { loading, error, data, client, refetch } = useListIngestionSourcesQuery({
variables: {
input: {
start,
count: pageSize,
query,
},
},
fetchPolicy: 'cache-first',
});
const [createIngestionSource] = useCreateIngestionSourceMutation();
const [updateIngestionSource] = useUpdateIngestionSourceMutation();
Expand Down Expand Up @@ -197,6 +198,16 @@ export const IngestionSourceList = () => {
});
} else {
// Create
const newSource = {
urn: 'placeholder-urn',
name: input.name,
type: input.type,
config: null,
schedule: null,
platform: null,
executions: null,
};
addToListIngestionSourcesCache(client, newSource, pageSize, query);
createIngestionSource({ variables: { input } })
.then((result) => {
message.loading({ content: 'Loading...', duration: 2 });
Expand Down Expand Up @@ -236,6 +247,7 @@ export const IngestionSourceList = () => {
};

const deleteIngestionSource = async (urn: string) => {
removeFromListIngestionSourcesCache(client, urn, page, pageSize, query);
removeIngestionSourceMutation({
variables: { urn },
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function IngestionSourceTable({
source.executions?.total &&
source.executions?.total > 0 &&
source.executions?.executionRequests[0].result?.status,
cliIngestion: source.config.executorId === CLI_EXECUTOR_ID,
cliIngestion: source.config?.executorId === CLI_EXECUTOR_ID,
}));

return (
Expand Down
83 changes: 83 additions & 0 deletions datahub-web-react/src/app/ingest/source/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { EntityType, FacetMetadata } from '../../../types.generated';
import { capitalizeFirstLetterOnly, pluralize } from '../../shared/textUtil';
import EntityRegistry from '../../entity/EntityRegistry';
import { SourceConfig } from './builder/types';
import { ListIngestionSourcesDocument, ListIngestionSourcesQuery } from '../../../graphql/ingestion.generated';

export const getSourceConfigs = (ingestionSources: SourceConfig[], sourceType: string) => {
const sourceConfigs = ingestionSources.find((source) => source.name === sourceType);
Expand Down Expand Up @@ -171,3 +172,85 @@ export const extractEntityTypeCountsFromFacets = (

return finalCounts;
};

/**
* Add an entry to the ListIngestionSources cache.
*/
export const addToListIngestionSourcesCache = (client, newSource, pageSize, query) => {
// Read the data from our cache for this query.
const currData: ListIngestionSourcesQuery | null = client.readQuery({
query: ListIngestionSourcesDocument,
variables: {
input: {
start: 0,
count: pageSize,
query,
},
},
});

// Add our new source into the existing list.
const newSources = [newSource, ...(currData?.listIngestionSources?.ingestionSources || [])];

// Write our data back to the cache.
client.writeQuery({
query: ListIngestionSourcesDocument,
variables: {
input: {
start: 0,
count: pageSize,
query,
},
},
data: {
listIngestionSources: {
start: 0,
count: (currData?.listIngestionSources?.count || 0) + 1,
total: (currData?.listIngestionSources?.total || 0) + 1,
ingestionSources: newSources,
},
},
});
};

/**
* Remove an entry from the ListIngestionSources cache.
*/
export const removeFromListIngestionSourcesCache = (client, urn, page, pageSize, query) => {
// Read the data from our cache for this query.
const currData: ListIngestionSourcesQuery | null = client.readQuery({
query: ListIngestionSourcesDocument,
variables: {
input: {
start: (page - 1) * pageSize,
count: pageSize,
query,
},
},
});

// Remove the source from the existing sources set.
const newSources = [
...(currData?.listIngestionSources?.ingestionSources || []).filter((source) => source.urn !== urn),
];

// Write our data back to the cache.
client.writeQuery({
query: ListIngestionSourcesDocument,
variables: {
input: {
start: (page - 1) * pageSize,
count: pageSize,
query,
},
},
data: {
listIngestionSources: {
start: currData?.listIngestionSources?.start || 0,
count: (currData?.listIngestionSources?.count || 1) - 1,
total: (currData?.listIngestionSources?.total || 1) - 1,
ingestionSources: newSources,
},
},
});
};

0 comments on commit 18a6c7f

Please sign in to comment.