Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -32,6 +32,7 @@
import { SearchSource, SearchSourceDependencies } from './search_source';
import { IndexPatternsContract } from '../../index_patterns/index_patterns';
import { SearchSourceFields } from './types';
import { DEFAULT_DATA } from '../../constants';

/**
* Deserializes a json string and a set of referenced objects to a `SearchSource` instance.
Expand All @@ -57,8 +58,13 @@
const fields = { ...searchSourceFields };

// hydrating index pattern
if (fields.index && typeof fields.index === 'string') {
fields.index = await indexPatterns.get(searchSourceFields.index as any);
if (
fields.index &&
typeof fields.index === 'string' &&
(!fields.query?.dataset?.type ||
fields.query.dataset.type === DEFAULT_DATA.SET_TYPES.INDEX_PATTERN)
) {
fields.index = await indexPatterns.get(fields.index as string);

Check warning on line 67 in src/plugins/data/common/search/search_source/create_search_source.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/data/common/search/search_source/create_search_source.ts#L67

Added line #L67 was not covered by tests
}

const searchSource = new SearchSource(fields, searchSourceDependencies);
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ export {
DQLBody,
SingleLineInput,
DatasetSelector,
AdvancedSelector,
NoIndexPatternsPanel,
DatasetSelectorAppearance,
} from './ui';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { RootState, DefaultViewState } from '../../../../../data_explorer/public
import { buildColumns } from '../columns';
import * as utils from './common';
import { SortOrder } from '../../../saved_searches/types';
import { DEFAULT_COLUMNS_SETTING, PLUGIN_ID } from '../../../../common';
import {
DEFAULT_COLUMNS_SETTING,
PLUGIN_ID,
QUERY_ENHANCEMENT_ENABLED_SETTING,
} from '../../../../common';

export interface DiscoverState {
/**
Expand Down Expand Up @@ -90,7 +94,8 @@ export const getPreloadedState = async ({
const indexPatternId = savedSearchInstance.searchSource.getField('index')?.id;
preloadedState.root = {
metadata: {
indexPattern: indexPatternId,
...(indexPatternId &&
!config.get(QUERY_ENHANCEMENT_ENABLED_SETTING) && { indexPattern: indexPatternId }),
view: PLUGIN_ID,
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,16 +354,34 @@
const savedSearchInstance = await getSavedSearchById(savedSearchId);
setSavedSearch(savedSearchInstance);

// if saved search does not exist, do not atempt to sync filters and query from savedObject
if (!savedSearch) {
return;
const query =
savedSearchInstance.searchSource.getField('query') ||
data.query.queryString.getDefaultQuery();

const isEnhancementsEnabled = await uiSettings.get('query:enhancements:enabled');

Check warning on line 361 in src/plugins/discover/public/application/view_components/utils/use_search.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/utils/use_search.ts#L361

Added line #L361 was not covered by tests
if (isEnhancementsEnabled && query.dataset) {
let pattern = await data.indexPatterns.get(

Check warning on line 363 in src/plugins/discover/public/application/view_components/utils/use_search.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/utils/use_search.ts#L363

Added line #L363 was not covered by tests
query.dataset.id,
query.dataset.type !== 'INDEX_PATTERN'
);
if (!pattern) {
await data.query.queryString.getDatasetService().cacheDataset(query.dataset, {

Check warning on line 368 in src/plugins/discover/public/application/view_components/utils/use_search.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/utils/use_search.ts#L368

Added line #L368 was not covered by tests
uiSettings: services.uiSettings,
savedObjects: services.savedObjects,
notifications: services.notifications,
http: services.http,
data: services.data,
});
pattern = await data.indexPatterns.get(

Check warning on line 375 in src/plugins/discover/public/application/view_components/utils/use_search.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/utils/use_search.ts#L375

Added line #L375 was not covered by tests
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for my knowledge, this just reads from cache and doesn't make a request? If it does make a request, I'm a little confused by the sequence above (call, cache, call) - I'm assuming the cache call is actually what fetches given this usage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question.

for anything that isn't an index pattern, it will read just from the cache. if nothing returns from the cache, then we will recreate the the dataset and save it as an index pattern when we call cache dataset. then we retrieve the actual index pattern we just created.

if it is an index pattern it will check the cache if it doesn't exist in the cache it will make it a request

query.dataset.id,
query.dataset.type !== 'INDEX_PATTERN'
);
savedSearchInstance.searchSource.setField('index', pattern);

Check warning on line 379 in src/plugins/discover/public/application/view_components/utils/use_search.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/discover/public/application/view_components/utils/use_search.ts#L379

Added line #L379 was not covered by tests
}
}

// sync initial app filters from savedObject to filterManager
const filters = cloneDeep(savedSearchInstance.searchSource.getOwnField('filter'));
const query =
savedSearchInstance.searchSource.getField('query') ||
data.query.queryString.getDefaultQuery();
const actualFilters = [];

if (filters !== undefined) {
Expand All @@ -387,8 +405,6 @@
);
}
})();

return () => {};
// This effect will only run when getSavedSearchById is called, which is
// only called when the component is first mounted.
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down
Loading