Skip to content

Commit

Permalink
[index pattern management] load index pattern list without loading fi…
Browse files Browse the repository at this point in the history
…eld lists (elastic#108823)

* don't load field list for index pattern list
  • Loading branch information
mattkime committed Aug 17, 2021
1 parent 3f7d3a8 commit 985a098
Show file tree
Hide file tree
Showing 26 changed files with 310 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternListItem](./kibana-plugin-plugins-data-public.indexpatternlistitem.md) &gt; [id](./kibana-plugin-plugins-data-public.indexpatternlistitem.id.md)

## IndexPatternListItem.id property

<b>Signature:</b>

```typescript
id: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternListItem](./kibana-plugin-plugins-data-public.indexpatternlistitem.md)

## IndexPatternListItem interface

<b>Signature:</b>

```typescript
export interface IndexPatternListItem
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [id](./kibana-plugin-plugins-data-public.indexpatternlistitem.id.md) | <code>string</code> | |
| [title](./kibana-plugin-plugins-data-public.indexpatternlistitem.title.md) | <code>string</code> | |
| [type](./kibana-plugin-plugins-data-public.indexpatternlistitem.type.md) | <code>string</code> | |
| [typeMeta](./kibana-plugin-plugins-data-public.indexpatternlistitem.typemeta.md) | <code>TypeMeta</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternListItem](./kibana-plugin-plugins-data-public.indexpatternlistitem.md) &gt; [title](./kibana-plugin-plugins-data-public.indexpatternlistitem.title.md)

## IndexPatternListItem.title property

<b>Signature:</b>

```typescript
title: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternListItem](./kibana-plugin-plugins-data-public.indexpatternlistitem.md) &gt; [type](./kibana-plugin-plugins-data-public.indexpatternlistitem.type.md)

## IndexPatternListItem.type property

<b>Signature:</b>

```typescript
type?: string;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [IndexPatternListItem](./kibana-plugin-plugins-data-public.indexpatternlistitem.md) &gt; [typeMeta](./kibana-plugin-plugins-data-public.indexpatternlistitem.typemeta.md)

## IndexPatternListItem.typeMeta property

<b>Signature:</b>

```typescript
typeMeta?: TypeMeta;
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
getCache: () => Promise<SavedObject<IndexPatternSavedObjectAttrs>[] | null | undefined>;
getCache: () => Promise<SavedObject<Pick<IndexPatternAttributes, "type" | "title" | "typeMeta">>[] | null | undefined>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ Get list of index pattern ids with titles
<b>Signature:</b>

```typescript
getIdsWithTitle: (refresh?: boolean) => Promise<Array<{
id: string;
title: string;
}>>;
getIdsWithTitle: (refresh?: boolean) => Promise<IndexPatternListItem[]>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export declare class IndexPatternsService
| [fieldArrayToMap](./kibana-plugin-plugins-data-public.indexpatternsservice.fieldarraytomap.md) | | <code>(fields: FieldSpec[], fieldAttrs?: FieldAttrs &#124; undefined) =&gt; Record&lt;string, FieldSpec&gt;</code> | Converts field array to map |
| [find](./kibana-plugin-plugins-data-public.indexpatternsservice.find.md) | | <code>(search: string, size?: number) =&gt; Promise&lt;IndexPattern[]&gt;</code> | Find and load index patterns by title |
| [get](./kibana-plugin-plugins-data-public.indexpatternsservice.get.md) | | <code>(id: string) =&gt; Promise&lt;IndexPattern&gt;</code> | Get an index pattern by id. Cache optimized |
| [getCache](./kibana-plugin-plugins-data-public.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;IndexPatternSavedObjectAttrs&gt;[] &#124; null &#124; undefined&gt;</code> | |
| [getCache](./kibana-plugin-plugins-data-public.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;Pick&lt;IndexPatternAttributes, &quot;type&quot; &#124; &quot;title&quot; &#124; &quot;typeMeta&quot;&gt;&gt;[] &#124; null &#124; undefined&gt;</code> | |
| [getDefault](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefault.md) | | <code>() =&gt; Promise&lt;IndexPattern &#124; null&gt;</code> | Get default index pattern |
| [getDefaultId](./kibana-plugin-plugins-data-public.indexpatternsservice.getdefaultid.md) | | <code>() =&gt; Promise&lt;string &#124; null&gt;</code> | Get default index pattern id |
| [getFieldsForIndexPattern](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforindexpattern.md) | | <code>(indexPattern: IndexPattern &#124; IndexPatternSpec, options?: GetFieldsOptions &#124; undefined) =&gt; Promise&lt;any&gt;</code> | Get field list by providing an index patttern (or spec) |
| [getFieldsForWildcard](./kibana-plugin-plugins-data-public.indexpatternsservice.getfieldsforwildcard.md) | | <code>(options: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing { pattern } |
| [getIds](./kibana-plugin-plugins-data-public.indexpatternsservice.getids.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern ids |
| [getIdsWithTitle](./kibana-plugin-plugins-data-public.indexpatternsservice.getidswithtitle.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;Array&lt;{</code><br/><code> id: string;</code><br/><code> title: string;</code><br/><code> }&gt;&gt;</code> | Get list of index pattern ids with titles |
| [getIdsWithTitle](./kibana-plugin-plugins-data-public.indexpatternsservice.getidswithtitle.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;IndexPatternListItem[]&gt;</code> | Get list of index pattern ids with titles |
| [getTitles](./kibana-plugin-plugins-data-public.indexpatternsservice.gettitles.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern titles |
| [refreshFields](./kibana-plugin-plugins-data-public.indexpatternsservice.refreshfields.md) | | <code>(indexPattern: IndexPattern) =&gt; Promise&lt;void&gt;</code> | Refresh field list for a given index pattern |
| [savedObjectToSpec](./kibana-plugin-plugins-data-public.indexpatternsservice.savedobjecttospec.md) | | <code>(savedObject: SavedObject&lt;IndexPatternAttributes&gt;) =&gt; IndexPatternSpec</code> | Converts index pattern saved object to index pattern spec |
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
| [IKibanaSearchRequest](./kibana-plugin-plugins-data-public.ikibanasearchrequest.md) | |
| [IKibanaSearchResponse](./kibana-plugin-plugins-data-public.ikibanasearchresponse.md) | |
| [IndexPatternAttributes](./kibana-plugin-plugins-data-public.indexpatternattributes.md) | Interface for an index pattern saved object |
| [IndexPatternListItem](./kibana-plugin-plugins-data-public.indexpatternlistitem.md) | |
| [IndexPatternSpec](./kibana-plugin-plugins-data-public.indexpatternspec.md) | Static index pattern format Serialized data object, representing index pattern attributes and state |
| [IndexPatternTypeMeta](./kibana-plugin-plugins-data-public.indexpatterntypemeta.md) | |
| [ISearchOptions](./kibana-plugin-plugins-data-public.isearchoptions.md) | |
| [ISearchSetup](./kibana-plugin-plugins-data-public.isearchsetup.md) | The setup contract exposed by the Search plugin exposes the search strategy extension point. |
| [ISearchStart](./kibana-plugin-plugins-data-public.isearchstart.md) | search service |
Expand All @@ -96,6 +96,7 @@
| [SearchInterceptorDeps](./kibana-plugin-plugins-data-public.searchinterceptordeps.md) | |
| [SearchSessionInfoProvider](./kibana-plugin-plugins-data-public.searchsessioninfoprovider.md) | Provide info about current search session to be stored in the Search Session saved object |
| [SearchSourceFields](./kibana-plugin-plugins-data-public.searchsourcefields.md) | search source fields |
| [TypeMeta](./kibana-plugin-plugins-data-public.typemeta.md) | |
| [WaitUntilNextSessionCompletesOptions](./kibana-plugin-plugins-data-public.waituntilnextsessioncompletesoptions.md) | Options for [waitUntilNextSessionCompletes$()](./kibana-plugin-plugins-data-public.waituntilnextsessioncompletes_.md) |

## Variables
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [TypeMeta](./kibana-plugin-plugins-data-public.typemeta.md) &gt; [aggs](./kibana-plugin-plugins-data-public.typemeta.aggs.md)

## TypeMeta.aggs property

<b>Signature:</b>

```typescript
aggs?: Record<string, AggregationRestrictions>;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [TypeMeta](./kibana-plugin-plugins-data-public.typemeta.md)

## TypeMeta interface

<b>Signature:</b>

```typescript
export interface TypeMeta
```

## Properties

| Property | Type | Description |
| --- | --- | --- |
| [aggs](./kibana-plugin-plugins-data-public.typemeta.aggs.md) | <code>Record&lt;string, AggregationRestrictions&gt;</code> | |
| [params](./kibana-plugin-plugins-data-public.typemeta.params.md) | <code>{</code><br/><code> rollup_index: string;</code><br/><code> }</code> | |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [kibana-plugin-plugins-data-public](./kibana-plugin-plugins-data-public.md) &gt; [TypeMeta](./kibana-plugin-plugins-data-public.typemeta.md) &gt; [params](./kibana-plugin-plugins-data-public.typemeta.params.md)

## TypeMeta.params property

<b>Signature:</b>

```typescript
params?: {
rollup_index: string;
};
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
<b>Signature:</b>

```typescript
getCache: () => Promise<SavedObject<IndexPatternSavedObjectAttrs>[] | null | undefined>;
getCache: () => Promise<SavedObject<Pick<IndexPatternAttributes, "type" | "title" | "typeMeta">>[] | null | undefined>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,5 @@ Get list of index pattern ids with titles
<b>Signature:</b>

```typescript
getIdsWithTitle: (refresh?: boolean) => Promise<Array<{
id: string;
title: string;
}>>;
getIdsWithTitle: (refresh?: boolean) => Promise<IndexPatternListItem[]>;
```
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ export declare class IndexPatternsService
| [fieldArrayToMap](./kibana-plugin-plugins-data-server.indexpatternsservice.fieldarraytomap.md) | | <code>(fields: FieldSpec[], fieldAttrs?: FieldAttrs &#124; undefined) =&gt; Record&lt;string, FieldSpec&gt;</code> | Converts field array to map |
| [find](./kibana-plugin-plugins-data-server.indexpatternsservice.find.md) | | <code>(search: string, size?: number) =&gt; Promise&lt;IndexPattern[]&gt;</code> | Find and load index patterns by title |
| [get](./kibana-plugin-plugins-data-server.indexpatternsservice.get.md) | | <code>(id: string) =&gt; Promise&lt;IndexPattern&gt;</code> | Get an index pattern by id. Cache optimized |
| [getCache](./kibana-plugin-plugins-data-server.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;IndexPatternSavedObjectAttrs&gt;[] &#124; null &#124; undefined&gt;</code> | |
| [getCache](./kibana-plugin-plugins-data-server.indexpatternsservice.getcache.md) | | <code>() =&gt; Promise&lt;SavedObject&lt;Pick&lt;IndexPatternAttributes, &quot;type&quot; &#124; &quot;title&quot; &#124; &quot;typeMeta&quot;&gt;&gt;[] &#124; null &#124; undefined&gt;</code> | |
| [getDefault](./kibana-plugin-plugins-data-server.indexpatternsservice.getdefault.md) | | <code>() =&gt; Promise&lt;IndexPattern &#124; null&gt;</code> | Get default index pattern |
| [getDefaultId](./kibana-plugin-plugins-data-server.indexpatternsservice.getdefaultid.md) | | <code>() =&gt; Promise&lt;string &#124; null&gt;</code> | Get default index pattern id |
| [getFieldsForIndexPattern](./kibana-plugin-plugins-data-server.indexpatternsservice.getfieldsforindexpattern.md) | | <code>(indexPattern: IndexPattern &#124; IndexPatternSpec, options?: GetFieldsOptions &#124; undefined) =&gt; Promise&lt;any&gt;</code> | Get field list by providing an index patttern (or spec) |
| [getFieldsForWildcard](./kibana-plugin-plugins-data-server.indexpatternsservice.getfieldsforwildcard.md) | | <code>(options: GetFieldsOptions) =&gt; Promise&lt;any&gt;</code> | Get field list by providing { pattern } |
| [getIds](./kibana-plugin-plugins-data-server.indexpatternsservice.getids.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern ids |
| [getIdsWithTitle](./kibana-plugin-plugins-data-server.indexpatternsservice.getidswithtitle.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;Array&lt;{</code><br/><code> id: string;</code><br/><code> title: string;</code><br/><code> }&gt;&gt;</code> | Get list of index pattern ids with titles |
| [getIdsWithTitle](./kibana-plugin-plugins-data-server.indexpatternsservice.getidswithtitle.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;IndexPatternListItem[]&gt;</code> | Get list of index pattern ids with titles |
| [getTitles](./kibana-plugin-plugins-data-server.indexpatternsservice.gettitles.md) | | <code>(refresh?: boolean) =&gt; Promise&lt;string[]&gt;</code> | Get list of index pattern titles |
| [refreshFields](./kibana-plugin-plugins-data-server.indexpatternsservice.refreshfields.md) | | <code>(indexPattern: IndexPattern) =&gt; Promise&lt;void&gt;</code> | Refresh field list for a given index pattern |
| [savedObjectToSpec](./kibana-plugin-plugins-data-server.indexpatternsservice.savedobjecttospec.md) | | <code>(savedObject: SavedObject&lt;IndexPatternAttributes&gt;) =&gt; IndexPatternSpec</code> | Converts index pattern saved object to index pattern spec |
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/common/index_patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
export * from './fields';
export * from './types';
export { IndexPatternsService, IndexPatternsContract } from './index_patterns';
export type { IndexPattern } from './index_patterns';
export type { IndexPattern, IndexPatternListItem } from './index_patterns';
export * from './errors';
export * from './expressions';
export * from './constants';
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ describe('IndexPatterns', () => {
expect((await indexPatterns.get(id)).fields.length).toBe(1);
});

test('savedObjectCache pre-fetches only title', async () => {
test('savedObjectCache pre-fetches title, type, typeMeta', async () => {
expect(await indexPatterns.getIds()).toEqual(['id']);
expect(savedObjectsClient.find).toHaveBeenCalledWith({
type: 'index-pattern',
fields: ['title'],
fields: ['title', 'type', 'typeMeta'],
perPage: 10000,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
FieldAttrs,
FieldSpec,
IndexPatternFieldMap,
TypeMeta,
} from '../types';
import { FieldFormatsStartCommon } from '../../field_formats';
import { UI_SETTINGS, SavedObject } from '../../../common';
Expand All @@ -40,8 +41,21 @@ import { castEsToKbnFieldTypeName } from '../../kbn_field_types';

const MAX_ATTEMPTS_TO_RESOLVE_CONFLICTS = 3;

export interface IndexPatternSavedObjectAttrs {
export type IndexPatternSavedObjectAttrs = Pick<
IndexPatternAttributes,
'title' | 'type' | 'typeMeta'
>;

export type IndexPatternListSavedObjectAttrs = Pick<
IndexPatternAttributes,
'title' | 'type' | 'typeMeta'
>;

export interface IndexPatternListItem {
id: string;
title: string;
type?: string;
typeMeta?: TypeMeta;
}

interface IndexPatternsServiceDeps {
Expand Down Expand Up @@ -98,7 +112,7 @@ export class IndexPatternsService {
private async refreshSavedObjectsCache() {
const so = await this.savedObjectsClient.find<IndexPatternSavedObjectAttrs>({
type: INDEX_PATTERN_SAVED_OBJECT_TYPE,
fields: ['title'],
fields: ['title', 'type', 'typeMeta'],
perPage: 10000,
});
this.savedObjectsCache = so;
Expand Down Expand Up @@ -156,9 +170,7 @@ export class IndexPatternsService {
* Get list of index pattern ids with titles
* @param refresh Force refresh of index pattern list
*/
getIdsWithTitle = async (
refresh: boolean = false
): Promise<Array<{ id: string; title: string }>> => {
getIdsWithTitle = async (refresh: boolean = false): Promise<IndexPatternListItem[]> => {
if (!this.savedObjectsCache || refresh) {
await this.refreshSavedObjectsCache();
}
Expand All @@ -168,6 +180,8 @@ export class IndexPatternsService {
return this.savedObjectsCache.map((obj) => ({
id: obj?.id,
title: obj?.attributes?.title,
type: obj?.attributes?.type,
typeMeta: obj?.attributes?.typeMeta && JSON.parse(obj?.attributes?.typeMeta),
}));
};

Expand Down Expand Up @@ -591,7 +605,7 @@ export class IndexPatternsService {
const createdIndexPattern = await this.initFromSavedObject(response);
this.indexPatternCache.set(createdIndexPattern.id!, Promise.resolve(createdIndexPattern));
if (this.savedObjectsCache) {
this.savedObjectsCache.push(response as SavedObject<IndexPatternSavedObjectAttrs>);
this.savedObjectsCache.push(response as SavedObject<IndexPatternListSavedObjectAttrs>);
}
return createdIndexPattern;
}
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export {
IndexPattern,
IIndexPatternFieldList,
IndexPatternField,
TypeMeta,
} from './index_patterns';

export {
Expand All @@ -270,6 +271,7 @@ export {
fieldList,
INDEX_PATTERN_SAVED_OBJECT_TYPE,
IndexPatternType,
IndexPatternListItem,
} from '../common';

export { DuplicateIndexPatternError } from '../common/index_patterns/errors';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/data/public/index_patterns/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export {
onUnsupportedTimePattern,
} from './index_patterns';

export { IndexPatternField, IIndexPatternFieldList } from '../../common/index_patterns';
export { IndexPatternField, IIndexPatternFieldList, TypeMeta } from '../../common/index_patterns';

export {
IndexPatternsService,
Expand Down
Loading

0 comments on commit 985a098

Please sign in to comment.