Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[discover] cached data structures TTL #8271

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
[data] cached data structures TTL
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
commit 97e74259f79103d64859ff20ca7dded176055a91
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
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
Loading