From 47b8d8505bc4f9ac451cd6cecae9e8023c17b9f0 Mon Sep 17 00:00:00 2001 From: Ryan Liang Date: Tue, 12 Mar 2024 19:33:35 -0700 Subject: [PATCH] Rebase after apply new interface 1 Signed-off-by: Ryan Liang --- .../accelerations/acceleration_table.tsx | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/public/components/datasources/components/manage/accelerations/acceleration_table.tsx b/public/components/datasources/components/manage/accelerations/acceleration_table.tsx index 8761f500ea..86052e94ac 100644 --- a/public/components/datasources/components/manage/accelerations/acceleration_table.tsx +++ b/public/components/datasources/components/manage/accelerations/acceleration_table.tsx @@ -29,45 +29,55 @@ import { CachedAccelerations, CachedDataSourceStatus, } from '../../../../../../common/types/data_connections'; -import { useAccelerationsToCache } from '../../../../../framework/catalog_cache/cache_loader'; +import { useLoadAccelerationsToCache } from '../../../../../framework/catalog_cache/cache_loader'; import { DirectQueryLoadingStatus } from '../../../../../../common/types/explorer'; export const AccelerationTable = () => { const [accelerations, setAccelerations] = useState([]); - const { loadStatus, startLoading: loadAccelerations } = useAccelerationsToCache(); + const { loadStatus, startLoading: loadAccelerations } = useLoadAccelerationsToCache(); const [isRefreshing, setIsRefreshing] = useState(false); + const dataSourceName = 'mys3'; // Example dataSource name useEffect(() => { async function checkAndLoadAccelerations() { - const cachedAccelerations = CatalogCacheManager.getAccelerationsCache(); + const accelerationsCache = CatalogCacheManager.getAccelerationsCache(); + const cachedDataSource = accelerationsCache.dataSources.find( + (ds) => ds.name === dataSourceName + ); if ( - (cachedAccelerations.status === CachedDataSourceStatus.Empty || - !cachedAccelerations.lastUpdated) && - !isRefreshing + !cachedDataSource || + cachedDataSource.status === CachedDataSourceStatus.Empty || + !cachedDataSource.lastUpdated ) { - // TODO: REMOVE THIS DEBUG MSG - console.log('Cache is empty or outdated. Loading accelerations...'); + console.log('Cache for dataSource is empty or outdated. Loading accelerations...'); setIsRefreshing(true); - await loadAccelerations('mys3'); + loadAccelerations(dataSourceName); + } else if (cachedDataSource && cachedDataSource.accelerations) { + console.log('Using cached accelerations for dataSource:', dataSourceName); + setAccelerations(cachedDataSource.accelerations); } } checkAndLoadAccelerations(); - }, [isRefreshing, loadAccelerations]); + }, [isRefreshing, loadAccelerations, dataSourceName]); useEffect(() => { if ( loadStatus === DirectQueryLoadingStatus.SUCCESS || loadStatus === DirectQueryLoadingStatus.FAILED ) { - // TODO: REMOVE THIS DEBUG MSG - console.log(`Load status: ${loadStatus}. Updating cache...`); + console.log( + `Load status: ${loadStatus}. Updating cache for dataSource: ${dataSourceName}...` + ); const updatedCache = CatalogCacheManager.getAccelerationsCache(); - setAccelerations(updatedCache.accelerations); + const updatedDataSource = updatedCache.dataSources.find((ds) => ds.name === dataSourceName); + if (updatedDataSource && updatedDataSource.accelerations) { + setAccelerations(updatedDataSource.accelerations); + } setIsRefreshing(false); } - }, [loadStatus]); + }, [loadStatus, dataSourceName]); const handleRefresh = () => { console.log('Initiating refresh...');