Skip to content

Commit

Permalink
better caching, with test
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkime committed Jan 14, 2024
1 parent 765152d commit 416a785
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/plugins/data_views/common/data_views/data_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,7 @@ export class DataViewsService {
...options,
pattern: indexPattern.title as string,
allowHidden:
(indexPattern as DataViewSpec).allowHidden ||
(indexPattern as DataView)?.getAllowHidden() ||
undefined,
(indexPattern as DataViewSpec).allowHidden || (indexPattern as DataView)?.getAllowHidden(),
});

private getFieldsAndIndicesForDataView = async (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,25 @@ describe('IndexPatternsApiClient', () => {
});

test('uses the right URI to fetch fields for wildcard', async function () {
await indexPatternsApiClient.getFieldsForWildcard({ pattern: 'blah' });
await indexPatternsApiClient.getFieldsForWildcard({ pattern: 'blah', allowHidden: false });

expect(fetchSpy).toHaveBeenCalledWith(expectedPath, expect.any(Object));
expect(fetchSpy).toHaveBeenCalledWith(expectedPath, {
// not sure what asResponse is but the rest of the results are useful
asResponse: true,
headers: {
'user-hash': '',
},
query: {
allow_hidden: undefined,
allow_no_index: undefined,
apiVersion: '1',
fields: undefined,
include_unmapped: undefined,
meta_fields: undefined,
pattern: 'blah',
rollup_index: undefined,
type: undefined,
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ export class DataViewsApiClient implements IDataViewsApiClient {
? this.http.post<T>(url, { query, body, version, asResponse })
: this.http.fetch<T>(url, {
query,
version,
...cacheOptions,
asResponse,
headers: { 'user-hash': userHash },
Expand Down Expand Up @@ -104,7 +103,8 @@ export class DataViewsApiClient implements IDataViewsApiClient {
allow_no_index: allowNoIndex,
include_unmapped: includeUnmapped,
fields,
allow_hidden: allowHidden,
// default to undefined to keep value out of URL params and improve caching
allow_hidden: allowHidden || undefined,
...versionQueryParam,
},
indexFilter ? JSON.stringify({ index_filter: indexFilter }) : undefined,
Expand Down

0 comments on commit 416a785

Please sign in to comment.