-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Discover] fix auto-refresh #80635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Discover] fix auto-refresh #80635
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Licensed to Elasticsearch B.V. under one or more contributor | ||
| * license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright | ||
| * ownership. Elasticsearch B.V. licenses this file to you under | ||
| * the Apache License, Version 2.0 (the "License"); you may | ||
| * not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| import { QueryStringManager } from './query_string_manager'; | ||
| import { Storage } from '../../../../kibana_utils/public/storage'; | ||
| import { StubBrowserStorage } from 'test_utils/stub_browser_storage'; | ||
| import { coreMock } from '../../../../../core/public/mocks'; | ||
| import { Query } from '../../../common/query'; | ||
|
|
||
| describe('QueryStringManager', () => { | ||
| let service: QueryStringManager; | ||
|
|
||
| beforeEach(() => { | ||
| service = new QueryStringManager( | ||
| new Storage(new StubBrowserStorage()), | ||
| coreMock.createSetup().uiSettings | ||
| ); | ||
| }); | ||
|
|
||
| test('getUpdates$ is a cold emits only after query changes', () => { | ||
| const obs$ = service.getUpdates$(); | ||
| const emittedValues: Query[] = []; | ||
| obs$.subscribe((v) => { | ||
| emittedValues.push(v); | ||
| }); | ||
| expect(emittedValues).toHaveLength(0); | ||
|
|
||
| const newQuery = { query: 'new query', language: 'kquery' }; | ||
| service.setQuery(newQuery); | ||
| expect(emittedValues).toHaveLength(1); | ||
| expect(emittedValues[0]).toEqual(newQuery); | ||
|
|
||
| service.setQuery({ ...newQuery }); | ||
| expect(emittedValues).toHaveLength(1); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -193,7 +193,7 @@ app.directive('discoverApp', function () { | |
| function discoverController($element, $route, $scope, $timeout, $window, Promise, uiCapabilities) { | ||
| const { isDefault: isDefaultType } = indexPatternsUtils; | ||
| const subscriptions = new Subscription(); | ||
| const $fetchObservable = new Subject(); | ||
| const refetch$ = new Subject(); | ||
| let inspectorRequest; | ||
| const savedSearch = $route.current.locals.savedObjects.savedSearch; | ||
| $scope.searchSource = savedSearch.searchSource; | ||
|
|
@@ -267,7 +267,7 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise | |
| ); | ||
|
|
||
| if (changes.length) { | ||
| $fetchObservable.next(); | ||
| refetch$.next(); | ||
| } | ||
| }); | ||
| } | ||
|
|
@@ -634,12 +634,18 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise | |
|
|
||
| const init = _.once(() => { | ||
| $scope.updateDataSource().then(async () => { | ||
| const searchBarChanges = merge(data.query.state$, $fetchObservable).pipe(debounceTime(100)); | ||
| const fetch$ = merge( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of reverting to using individual observables and relying on the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the patch, but I think it would cause issue with excessive refetch on removing disabled filter which I mentioned in the description:
Also some thoughts on query.state$ vs fetch$: #80586 (comment)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed. Thanks for the feedback. |
||
| refetch$, | ||
| filterManager.getFetches$(), | ||
| timefilter.getFetch$(), | ||
| timefilter.getAutoRefreshFetch$(), | ||
| data.query.queryString.getUpdates$() | ||
| ).pipe(debounceTime(100)); | ||
|
|
||
| subscriptions.add( | ||
| subscribeWithScope( | ||
| $scope, | ||
| searchBarChanges, | ||
| fetch$, | ||
| { | ||
| next: $scope.fetch, | ||
| }, | ||
|
|
@@ -718,7 +724,7 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise | |
|
|
||
| init.complete = true; | ||
| if (shouldSearchOnPageLoad()) { | ||
| $fetchObservable.next(); | ||
| refetch$.next(); | ||
| } | ||
| }); | ||
| }); | ||
|
|
@@ -816,7 +822,7 @@ function discoverController($element, $route, $scope, $timeout, $window, Promise | |
|
|
||
| $scope.handleRefresh = function (_payload, isUpdate) { | ||
| if (isUpdate === false) { | ||
| $fetchObservable.next(); | ||
| refetch$.next(); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.