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

dataviews.clearCache cleanup #136256

Merged
merged 2 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export const IndexPatternTable = ({
id={dataView.id}
title={dataView.title}
refresh={() => {
dataViews.clearCache(dataView.id);
dataViews.clearInstanceCache(dataView.id);
loadDataViews();
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ describe('IndexPatterns', () => {

// Create a normal index patterns
const pattern = await indexPatterns.get('foo');
indexPatterns.clearCache();
indexPatterns.clearInstanceCache();

// Create the same one - we're going to handle concurrency
const samePattern = await indexPatterns.get('foo');
Expand Down
22 changes: 16 additions & 6 deletions src/plugins/data_views/common/data_views/data_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,15 @@ export interface DataViewsServiceDeps {
*/
export interface DataViewsServicePublicMethods {
/**
* Clear the cache of data views.
* @param id
* Clear the cache of data view saved objects.
*/
clearCache: (id?: string | undefined) => void;
clearCache: () => void;

/**
* Clear the cache of data view instances.
*/
clearInstanceCache: (id?: string) => void;

/**
* Create data view based on the provided spec.
* @param spec - Data view spec.
Expand Down Expand Up @@ -396,11 +401,16 @@ export class DataViewsService {
};

/**
* Clear index pattern list cache.
* @param id optionally clear a single id
* Clear index pattern saved objects cache.
*/
clearCache = (id?: string) => {
clearCache = () => {
this.savedObjectsCache = null;
};

/**
* Clear index pattern instance cache
*/
clearInstanceCache = (id?: string) => {
if (id) {
this.dataViewCache.clear(id);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function DiscoverMainRoute(props: Props) {

const ipList = ip.list as Array<SavedObject<DataViewAttributes>>;
const indexPatternData = resolveIndexPattern(ip, searchSource, toastNotifications);

await data.dataViews.refreshFields(indexPatternData);
setIndexPatternList(ipList);

return indexPatternData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ export function ChangeDataView({
panelItems.push(
<DataViewsList
dataViewsList={dataViewsList}
onChangeDataView={(newId) => {
onChangeDataView={async (newId) => {
const dataView = await data.dataViews.get(newId);
await data.dataViews.refreshFields(dataView);
onChangeDataView(newId);
setPopoverIsOpen(false);
}}
Expand Down