Skip to content

Commit

Permalink
dataviews.clearCache cleanup (#136256)
Browse files Browse the repository at this point in the history
  • Loading branch information
ppisljar authored Jul 18, 2022
1 parent bfa1968 commit 7fa6813
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
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

0 comments on commit 7fa6813

Please sign in to comment.