Skip to content

Commit

Permalink
added fix for cache and cahnged router
Browse files Browse the repository at this point in the history
Signed-off-by: sumukhswamy <[email protected]>
  • Loading branch information
sumukhswamy committed Apr 30, 2024
1 parent af04339 commit a241b90
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 148 deletions.
10 changes: 2 additions & 8 deletions common/types/data_connections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ export interface CachedDataSource {
lastUpdated: string; // date string in UTC format
status: CachedDataSourceStatus;
databases: CachedDatabase[];
dataSourceMDSId?: string;
}

export interface DataSourceCacheData {
dataSourceMDSId?: string;
version: string;
dataSources: CachedDataSource[];
}
Expand All @@ -144,11 +144,11 @@ export interface CachedAccelerationByDataSource {
accelerations: CachedAcceleration[];
lastUpdated: string; // date string in UTC format
status: CachedDataSourceStatus;
dataSourceMDSId?: string;
}

export interface AccelerationsCacheData {
version: string;
dataSourceMDSId?: string;
dataSources: CachedAccelerationByDataSource[];
}

Expand Down Expand Up @@ -239,12 +239,6 @@ export interface CreateAccelerationForm {
refreshIntervalOptions: RefreshIntervalType;
formErrors: FormErrorsType;
}
export interface StartLoadingParams {
dataSourceName: string;
dataSourceMDSId?: string;
databaseName?: string;
tableName?: string;
}

export interface LoadCachehookOutput {
loadStatus: DirectQueryLoadingStatus;
Expand Down
2 changes: 1 addition & 1 deletion common/utils/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export function get<T = unknown>(obj: Record<string, any>, path: string, default
}

export function addBackticksIfNeeded(input: string): string {
// Check if the string already has backticks
if (input === undefined) {
return '';
}
// Check if the string already has backticks
if (input.startsWith('`') && input.endsWith('`')) {
return input; // Return the string as it is
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export const CreateAcceleration = ({
selectedDatasource={selectedDatasource}
dataSourcesPreselected={dataSourcesPreselected}
tableFieldsLoading={tableFieldsLoading}
dataSourceMDSId={dataSourceMDSId}
/>
<EuiSpacer size="xxl" />
<IndexTypeSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import React, { useEffect, useState } from 'react';
import { CoreStart } from '../../../../../../../../../../src/core/public';
import { DATACONNECTIONS_BASE } from '../../../../../../../../common/constants/shared';
import {
CachedDatabase,
CachedDataSourceStatus,
CachedDatabase,
CreateAccelerationForm,
} from '../../../../../../../../common/types/data_connections';
import { CatalogCacheManager } from '../../../../../../../framework/catalog_cache/cache_manager';
import { useToast } from '../../../../../../common/toast';
import { hasError, validateDatabase, validateDataTable } from '../create/utils';
import { hasError, validateDataTable, validateDatabase } from '../create/utils';
import { SelectorLoadDatabases } from './selector_helpers/load_databases';
import { SelectorLoadObjects } from './selector_helpers/load_objects';

Expand All @@ -37,6 +37,7 @@ interface AccelerationDataSourceSelectorProps {
selectedDatasource: string;
dataSourcesPreselected: boolean;
tableFieldsLoading: boolean;
dataSourceMDSId?: string;
}

export const AccelerationDataSourceSelector = ({
Expand All @@ -46,6 +47,7 @@ export const AccelerationDataSourceSelector = ({
selectedDatasource,
dataSourcesPreselected,
tableFieldsLoading,
dataSourceMDSId,
}: AccelerationDataSourceSelectorProps) => {
const { setToast } = useToast();
const [databases, setDatabases] = useState<Array<EuiComboBoxOptionOption<string>>>([]);
Expand All @@ -72,7 +74,7 @@ export const AccelerationDataSourceSelector = ({
const loadDataSource = () => {
setLoadingComboBoxes({ ...loadingComboBoxes, dataSource: true });
http
.get(DATACONNECTIONS_BASE)
.get(DATACONNECTIONS_BASE + `/dataSourceMDSId=${dataSourceMDSId}`)
.then((res) => {
const isValidDataSource = res.some(
(connection: any) =>
Expand Down
2 changes: 1 addition & 1 deletion public/components/hooks/use_polling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export function usePolling<T, P = void>(
try {
const result = await fetchFunction(params);
setData(result);

console.log(result);
// Check the success condition and stop polling if it's met
if (onPollingSuccess && onPollingSuccess(result, configurations)) {
stopPolling();
Expand Down
83 changes: 51 additions & 32 deletions public/framework/catalog_cache/cache_loader.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,28 +66,44 @@ describe('loadCacheTests', () => {
updateDatabasesToCache(dataSourceName, pollingResult);

// Verify that addOrUpdateDataSource is called with the correct parameters
expect(CatalogCacheManager.addOrUpdateDataSource).toHaveBeenCalledWith({
name: dataSourceName,
databases: [],
lastUpdated: expect.any(String),
status: CachedDataSourceStatus.Failed,
});
expect(CatalogCacheManager.addOrUpdateDataSource).toHaveBeenCalledWith(
{
name: dataSourceName,
databases: [],
lastUpdated: expect.any(String),
status: CachedDataSourceStatus.Failed,
},
undefined
);
});

it('should update cache with new databases when polling result is not null', () => {
const dataSourceName = 'TestDataSource';
updateDatabasesToCache(dataSourceName, mockShowDatabasesPollingResult);

// Verify that addOrUpdateDataSource is called with the correct parameters
expect(CatalogCacheManager.addOrUpdateDataSource).toHaveBeenCalledWith({
name: dataSourceName,
databases: [
{ name: 'Database1', tables: [], lastUpdated: '', status: CachedDataSourceStatus.Empty },
{ name: 'Database2', tables: [], lastUpdated: '', status: CachedDataSourceStatus.Empty },
],
lastUpdated: expect.any(String),
status: CachedDataSourceStatus.Updated,
});
expect(CatalogCacheManager.addOrUpdateDataSource).toHaveBeenCalledWith(
{
name: dataSourceName,
databases: [
{
name: 'Database1',
tables: [],
lastUpdated: '',
status: CachedDataSourceStatus.Empty,
},
{
name: 'Database2',
tables: [],
lastUpdated: '',
status: CachedDataSourceStatus.Empty,
},
],
lastUpdated: expect.any(String),
status: CachedDataSourceStatus.Updated,
},
undefined
);
});
});

Expand All @@ -97,19 +113,22 @@ describe('loadCacheTests', () => {
const databaseName = 'TestDatabase';
const pollingResult = null;

CatalogCacheManager.addOrUpdateDataSource({
databases: [
{
name: databaseName,
lastUpdated: '',
status: CachedDataSourceStatus.Empty,
tables: [],
},
],
name: dataSourceName,
lastUpdated: new Date().toUTCString(),
status: CachedDataSourceStatus.Updated,
});
CatalogCacheManager.addOrUpdateDataSource(
{
databases: [
{
name: databaseName,
lastUpdated: '',
status: CachedDataSourceStatus.Empty,
tables: [],
},
],
name: dataSourceName,
lastUpdated: new Date().toUTCString(),
status: CachedDataSourceStatus.Updated,
},
undefined
);
updateTablesToCache(dataSourceName, databaseName, pollingResult);

// Verify that updateDatabase is called with the correct parameters
Expand All @@ -120,7 +139,8 @@ describe('loadCacheTests', () => {
tables: [],
lastUpdated: expect.any(String),
status: CachedDataSourceStatus.Failed,
})
}),
undefined
);
});

Expand Down Expand Up @@ -151,7 +171,8 @@ describe('loadCacheTests', () => {
tables: [{ name: 'http_logs1' }, { name: 'http_logs2' }],
lastUpdated: expect.any(String),
status: CachedDataSourceStatus.Updated,
})
}),
undefined
);
});
});
Expand All @@ -170,7 +191,6 @@ describe('loadCacheTests', () => {
// Verify that saveAccelerationsCache is called with the correct parameters
expect(CatalogCacheManager.saveAccelerationsCache).toHaveBeenCalledWith({
version: CATALOG_CACHE_VERSION,
dataSourceMDSId: '',
dataSources: [
{
name: 'sampleDS',
Expand All @@ -188,7 +208,6 @@ describe('loadCacheTests', () => {
// Verify that saveAccelerationsCache is called with the correct parameters
expect(CatalogCacheManager.saveAccelerationsCache).toHaveBeenCalledWith({
version: CATALOG_CACHE_VERSION,
dataSourceMDSId: '',
dataSources: [
{
name: 'sampleDS',
Expand Down
Loading

0 comments on commit a241b90

Please sign in to comment.