Skip to content

Commit

Permalink
[data] cached data structures TTL
Browse files Browse the repository at this point in the history
If the dataset type config passes a meta object with `updateAt`
within the data structure we know that the config opts into the TTL.

If TTL over configuring UI setting then refetch in the case of S3
to get a new session ID in the cache.

Signed-off-by: Kawika Avilla <kavilla414@gmail.com>
  • Loading branch information
kavilla committed Sep 23, 2024
1 parent f6924a7 commit 97e7425
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/plugins/data/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export const UI_SETTINGS = {
FILTERS_PINNED_BY_DEFAULT: 'filters:pinnedByDefault',
FILTERS_EDITOR_SUGGEST_VALUES: 'filterEditor:suggestValues',
QUERY_ENHANCEMENTS_ENABLED: 'query:enhancements:enabled',
QUERY_CACHED_DATA_STRUCTURES_TTL: 'query:cachedDataStructures:ttl',
QUERY_DATAFRAME_HYDRATION_STRATEGY: 'query:dataframe:hydrationStrategy',
SEARCH_QUERY_LANGUAGE_BLOCKLIST: 'search:queryLanguageBlocklist',
NEW_HOME_PAGE: 'home:useNewHomePage',
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/datasets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export interface DataStructureCustomMeta {
type: DATA_STRUCTURE_META_TYPES.CUSTOM;
icon?: EuiIconProps;
tooltip?: string;
updatedAt?: number;
[key: string]: any;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ export class DatasetService {
const cacheKey = `${dataType}.${lastPathItem.id}`;

const cachedDataStructure = this.sessionStorage.get<CachedDataStructure>(cacheKey);
if (cachedDataStructure?.children?.length > 0) {
if (
cachedDataStructure?.children?.length > 0 &&
(!cachedDataStructure?.meta?.updatedAt ||
Date.now() - cachedDataStructure?.meta?.updatedAt <
this.uiSettings.get(UI_SETTINGS.QUERY_CACHED_DATA_STRUCTURES_TTL))
) {
return this.cacheToDataStructure(dataType, cachedDataStructure);
}

Expand Down
14 changes: 14 additions & 0 deletions src/plugins/data/server/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,20 @@ export function getUiSettings(): Record<string, UiSettingsParams<unknown>> {
requiresPageReload: true,
schema: schema.boolean(),
},
[UI_SETTINGS.QUERY_CACHED_DATA_STRUCTURES_TTL]: {
name: i18n.translate('data.advancedSettings.query.cachedDataStructures.ttl', {
defaultMessage: 'Cached data structures TTL',
}),
value: 600000,
description: i18n.translate('data.advancedSettings.query.cachedDataStructures.ttl', {
defaultMessage: `
<strong>Experimental</strong>:
Cached data structures TTL before refetching if the data type has it configured.`,
}),
category: ['search'],
requiresPageReload: true,
schema: schema.oneOf([schema.number({ min: 0 }), schema.literal('Infinity')]),
},
[UI_SETTINGS.QUERY_DATAFRAME_HYDRATION_STRATEGY]: {
name: i18n.translate('data.advancedSettings.query.dataFrameHydrationStrategyTitle', {
defaultMessage: 'Data frame hydration strategy',
Expand Down
1 change: 1 addition & 0 deletions src/plugins/query_enhancements/public/datasets/s3_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ const setMeta = (dataStructure: DataStructure, response: any) => {
...dataStructure.meta,
queryId: response.queryId,
sessionId: response.sessionId,
updatedAt: Date.now(),
} as DataStructureCustomMeta;
};

Expand Down

0 comments on commit 97e7425

Please sign in to comment.