Skip to content

Commit

Permalink
fix async field fetch in cachedataset
Browse files Browse the repository at this point in the history
Signed-off-by: Shenoy Pratik <sgguruda@amazon.com>
  • Loading branch information
ps48 committed Oct 22, 2024
1 parent a096e61 commit 8f87349
Showing 1 changed file with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,17 @@ export class DatasetService {
): Promise<void> {
const type = this.getType(dataset?.type);
try {
const asyncType = type && type.meta.isFieldLoadAsync;
const asyncType = type?.meta.isFieldLoadAsync ?? false;
if (dataset && dataset.type !== DEFAULT_DATA.SET_TYPES.INDEX_PATTERN) {
const fetchedFields = asyncType
? await type?.fetchFields(dataset, services)
: ({} as IndexPatternFieldMap);
? ({} as IndexPatternFieldMap)
: await type?.fetchFields(dataset, services);
const spec = {
id: dataset.id,
title: dataset.title,
timeFieldName: dataset.timeFieldName,
fields: fetchedFields,
fieldsLoading: asyncType ? true : false,
fieldsLoading: asyncType,
dataSourceRef: dataset.dataSource
? {
id: dataset.dataSource.id!,
Expand All @@ -121,12 +121,15 @@ export class DatasetService {

// Load schema asynchronously if it's an async index pattern
if (asyncType && temporaryIndexPattern) {
type
type!

Check warning on line 124 in src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts#L124

Added line #L124 was not covered by tests
.fetchFields(dataset, services)
.then((fields) => {
temporaryIndexPattern?.fields.replaceAll([...fields]);
temporaryIndexPattern.fields.replaceAll([...fields]);
this.indexPatterns?.saveToCache(dataset.id, temporaryIndexPattern);

Check warning on line 128 in src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts#L127-L128

Added lines #L127 - L128 were not covered by tests
})
.catch((error) => {
throw new Error(`Error while fetching fields for dataset ${dataset.id}:`);

Check warning on line 131 in src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts#L131

Added line #L131 was not covered by tests
})
.finally(() => {
temporaryIndexPattern.setFieldsLoading(false);

Check warning on line 134 in src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/public/query/query_string/dataset_service/dataset_service.ts#L134

Added line #L134 was not covered by tests
});
Expand Down

0 comments on commit 8f87349

Please sign in to comment.